Fixes: SPA page tracking
This commit is contained in:
34
app/components/Analytics.js
Normal file
34
app/components/Analytics.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// @flow
|
||||||
|
/* global ga */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
export default class Analytics extends React.Component<*> {
|
||||||
|
componentDidMount() {
|
||||||
|
if (!process.env.GOOGLE_ANALYTICS_ID) return;
|
||||||
|
|
||||||
|
// standard Google Analytics script
|
||||||
|
window.ga =
|
||||||
|
window.ga ||
|
||||||
|
function() {
|
||||||
|
// $FlowIssue
|
||||||
|
(ga.q = ga.q || []).push(arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
// $FlowIssue
|
||||||
|
ga.l = +new Date();
|
||||||
|
ga('create', process.env.GOOGLE_ANALYTICS_ID, 'auto');
|
||||||
|
ga('send', 'pageview');
|
||||||
|
|
||||||
|
const script = document.createElement('script');
|
||||||
|
script.src = 'https://www.google-analytics.com/analytics.js';
|
||||||
|
script.async = true;
|
||||||
|
|
||||||
|
if (document.body) {
|
||||||
|
document.body.appendChild(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return this.props.children || null;
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ import styled from 'styled-components';
|
|||||||
import breakpoint from 'styled-components-breakpoint';
|
import breakpoint from 'styled-components-breakpoint';
|
||||||
import { observer, inject } from 'mobx-react';
|
import { observer, inject } from 'mobx-react';
|
||||||
import keydown from 'react-keydown';
|
import keydown from 'react-keydown';
|
||||||
import Analytics from 'shared/components/Analytics';
|
import Analytics from 'components/Analytics';
|
||||||
import Flex from 'shared/components/Flex';
|
import Flex from 'shared/components/Flex';
|
||||||
import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers';
|
import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers';
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { Helmet } from 'react-helmet';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import breakpoint from 'styled-components-breakpoint';
|
import breakpoint from 'styled-components-breakpoint';
|
||||||
import { TopNavigation, BottomNavigation } from './Navigation';
|
import { TopNavigation, BottomNavigation } from './Navigation';
|
||||||
import Analytics from '../../../shared/components/Analytics';
|
import Analytics from './Analytics';
|
||||||
import GlobalStyles from '../../../shared/styles/globals';
|
import GlobalStyles from '../../../shared/styles/globals';
|
||||||
import prefetchTags from '../../utils/prefetchTags';
|
import prefetchTags from '../../utils/prefetchTags';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user