From 88cd024c8c5f614bea828e9bd1e289056072f4e7 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 14 Aug 2019 23:09:34 -0400 Subject: [PATCH] cleanup reactGA events --- src/ui/analytics.js | 51 ++++++++++++----------------------- src/ui/component/app/view.jsx | 2 ++ 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/ui/analytics.js b/src/ui/analytics.js index 373a20ca2..1806e40b1 100644 --- a/src/ui/analytics.js +++ b/src/ui/analytics.js @@ -36,10 +36,7 @@ const analytics: Analytics = { // @if TARGET='app' Native.getAppVersionInfo().then(({ localVersion }) => { - ReactGA.event({ - category: 'Desktop-Version', - action: localVersion, - }); + sendGaEvent('Desktop-Version', localVersion); }); // @endif } @@ -88,47 +85,31 @@ const analytics: Analytics = { } }, tagFollowEvent: (tag, following, location) => { - if (analyticsEnabled) { - ReactGA.event({ - category: following ? 'Tag-Follow' : 'Tag-Unfollow', - action: tag, - }); - } + sendGaEvent(following ? 'Tag-Follow' : 'Tag-Unfollow', tag); }, channelBlockEvent: (uri, blocked, location) => { - if (analyticsEnabled) { - ReactGA.event({ - category: blocked ? 'Channel-Hidden' : 'Channel-Unhidden', - action: uri, - }); - } + sendGaEvent(blocked ? 'Channel-Hidden' : 'Channel-Unhidden', uri); }, emailProvidedEvent: () => { - if (analyticsEnabled && isProduction) { - ReactGA.event({ - category: 'Engagement', - action: 'Email-Provided', - }); - } + sendGaEvent('Engagement', 'Email-Provided'); }, emailVerifiedEvent: () => { - if (analyticsEnabled && isProduction) { - ReactGA.event({ - category: 'Engagement', - action: 'Email-Verified', - }); - } + sendGaEvent('Engagement', 'Email-Verified'); }, rewardEligibleEvent: () => { - if (analyticsEnabled && isProduction) { - ReactGA.event({ - category: 'Engagement', - action: 'Reward-Eligible', - }); - } + sendGaEvent('Engagement', 'Reward-Eligible'); }, }; +function sendGaEvent(category, action) { + if (analyticsEnabled && isProduction) { + ReactGA.event({ + category, + action, + }); + } +} + // Initialize google analytics // Set `debug: true` for debug info // Will change once we have separate ids for desktop/web @@ -143,6 +124,8 @@ ElectronCookies.enable({ ReactGA.initialize(UA_ID, { testMode: process.env.NODE_ENV !== 'production', cookieDomain: 'auto', + // un-comment to see events as they are sent to google + // debug: true, }); // Manually call the first page view diff --git a/src/ui/component/app/view.jsx b/src/ui/component/app/view.jsx index b337e9c93..6740470de 100644 --- a/src/ui/component/app/view.jsx +++ b/src/ui/component/app/view.jsx @@ -75,6 +75,8 @@ function App(props: Props) { }, [previousUserId, userId]); useEffect(() => { + // Check that previousHasVerifiedEmail was not undefined instead of just not truthy + // This ensures we don't fire the emailVerified event on the initial user fetch if (previousHasVerifiedEmail !== undefined && hasVerifiedEmail) { analytics.emailVerifiedEvent(); }