add google analytics

This commit is contained in:
Sean Yesmunt 2019-04-09 17:21:00 -04:00
parent 627acbd885
commit d9df91f2cf

View file

@ -1,6 +1,7 @@
// @flow // @flow
import { Lbryio } from 'lbryinc'; import { Lbryio } from 'lbryinc';
import ReactGA from 'react-ga'; import ReactGA from 'react-ga';
import { history } from './store';
type Analytics = { type Analytics = {
pageView: string => void, pageView: string => void,
@ -14,7 +15,7 @@ let analyticsEnabled: boolean = true;
const analytics: Analytics = { const analytics: Analytics = {
pageView: path => { pageView: path => {
if (analyticsEnabled) { if (analyticsEnabled) {
// ReactGA.pageview(path); ReactGA.pageview(path, IS_WEB ? 'web' : 'desktop');
} }
}, },
setUser: user => { setUser: user => {
@ -71,19 +72,22 @@ const analytics: Analytics = {
// Initialize google analytics // Initialize google analytics
// Set `debug: true` for debug info // Set `debug: true` for debug info
// ReactGA.initialize('UA-60403362-12', { ReactGA.initialize('UA-60403362-12', {
// gaOptions: { name: IS_WEB ? 'web' : 'desktop' }, gaOptions: { name: IS_WEB ? 'web' : 'desktop' },
// testMode: process.env.NODE_ENV !== 'production', testMode: process.env.NODE_ENV !== 'production',
// }); debug: true,
});
// Manually call the first page view // Manually call the first page view
// Reach Router doesn't include this on `history.listen` // React Router doesn't include this on `history.listen`
// analytics.pageView(window.location.pathname + window.location.search); analytics.pageView(window.location.pathname + window.location.search);
// Listen for url changes and report // Listen for url changes and report
// This will include search queries/filter options // This will include search queries
// globalHistory.listen(({ location }) => history.listen(location => {
// analytics.pageView(window.location.pathname + window.location.search) const { pathname, search } = location;
// ); const page = `${pathname}${search}`;
analytics.pageView(page);
});
export default analytics; export default analytics;