From 12498b1b69a6e3cbcdd1cfcc0262ce93619ed793 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Sun, 21 Jul 2019 22:28:49 -0400 Subject: [PATCH] send ga event with user id --- src/ui/analytics.js | 15 ++++++++------- src/ui/component/app/view.jsx | 11 ++++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/ui/analytics.js b/src/ui/analytics.js index 6286ca2f5..a30af33c6 100644 --- a/src/ui/analytics.js +++ b/src/ui/analytics.js @@ -24,12 +24,14 @@ const analytics: Analytics = { ReactGA.pageview(path); } }, - setUser: user => { - // Commented out because currently there is some delay before we know the user - // We should retrieve this server side so we have it immediately - // if (analyticsEnabled && user.id) { - // ReactGA.set('userId', user.id); - // } + setUser: userId => { + if (analyticsEnabled && userId) { + ReactGA.event({ + category: 'User', + action: 'userId', + value: userId, + }); + } }, toggle: (enabled: boolean): void => { // Always collect analytics on lbry.tv @@ -80,7 +82,6 @@ const analytics: Analytics = { } }, tagFollowEvent: (tag, following, location) => { - console.log('yep'); if (analyticsEnabled) { ReactGA.event({ category: 'Tag', diff --git a/src/ui/component/app/view.jsx b/src/ui/component/app/view.jsx index 0c82d2233..fc28aa29c 100644 --- a/src/ui/component/app/view.jsx +++ b/src/ui/component/app/view.jsx @@ -1,5 +1,6 @@ // @flow import React, { useEffect, useRef } from 'react'; +import analytics from 'analytics'; import Router from 'component/router/index'; import ModalRouter from 'modal/modalRouter'; import ReactModal from 'react-modal'; @@ -16,15 +17,17 @@ type Props = { pageTitle: ?string, language: string, theme: string, + user: ?{ id: string }, fetchRewards: () => void, fetchRewardedContent: () => void, fetchTransactions: () => void, }; function App(props: Props) { - const { theme, fetchRewards, fetchRewardedContent, fetchTransactions } = props; + const { theme, fetchRewards, fetchRewardedContent, fetchTransactions, user } = props; const appRef = useRef(); const isEnhancedLayout = useKonamiListener(); + const userId = user && user.id; useEffect(() => { ReactModal.setAppElement(appRef.current); @@ -41,6 +44,12 @@ function App(props: Props) { document.documentElement.setAttribute('data-mode', theme); }, [theme]); + useEffect(() => { + if (userId) { + analytics.setUser(userId); + } + }, [userId]); + return (
openContextMenu(e)}>