add google analytics
This commit is contained in:
parent
627acbd885
commit
d9df91f2cf
1 changed files with 15 additions and 11 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue