From d9df91f2cf30fd0b352cfe4fa6c59e62e67e3200 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Tue, 9 Apr 2019 17:21:00 -0400 Subject: [PATCH] add google analytics --- src/ui/analytics.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ui/analytics.js b/src/ui/analytics.js index 57c9590df..104119a34 100644 --- a/src/ui/analytics.js +++ b/src/ui/analytics.js @@ -1,6 +1,7 @@ // @flow import { Lbryio } from 'lbryinc'; import ReactGA from 'react-ga'; +import { history } from './store'; type Analytics = { pageView: string => void, @@ -14,7 +15,7 @@ let analyticsEnabled: boolean = true; const analytics: Analytics = { pageView: path => { if (analyticsEnabled) { - // ReactGA.pageview(path); + ReactGA.pageview(path, IS_WEB ? 'web' : 'desktop'); } }, setUser: user => { @@ -71,19 +72,22 @@ const analytics: Analytics = { // Initialize google analytics // Set `debug: true` for debug info -// ReactGA.initialize('UA-60403362-12', { -// gaOptions: { name: IS_WEB ? 'web' : 'desktop' }, -// testMode: process.env.NODE_ENV !== 'production', -// }); +ReactGA.initialize('UA-60403362-12', { + gaOptions: { name: IS_WEB ? 'web' : 'desktop' }, + testMode: process.env.NODE_ENV !== 'production', + debug: true, +}); // Manually call the first page view -// Reach Router doesn't include this on `history.listen` -// analytics.pageView(window.location.pathname + window.location.search); +// React Router doesn't include this on `history.listen` +analytics.pageView(window.location.pathname + window.location.search); // Listen for url changes and report -// This will include search queries/filter options -// globalHistory.listen(({ location }) => -// analytics.pageView(window.location.pathname + window.location.search) -// ); +// This will include search queries +history.listen(location => { + const { pathname, search } = location; + const page = `${pathname}${search}`; + analytics.pageView(page); +}); export default analytics;