Insert ga tags in app
This commit is contained in:
@ -6,6 +6,7 @@ import { Helmet } from 'react-helmet';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
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 Flex from 'shared/components/Flex';
|
import Flex from 'shared/components/Flex';
|
||||||
import { color, layout } from 'shared/styles/constants';
|
import { color, layout } from 'shared/styles/constants';
|
||||||
import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers';
|
import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers';
|
||||||
@ -108,6 +109,7 @@ type Props = {
|
|||||||
content="width=device-width, initial-scale=1.0"
|
content="width=device-width, initial-scale=1.0"
|
||||||
/>
|
/>
|
||||||
</Helmet>
|
</Helmet>
|
||||||
|
<Analytics />
|
||||||
|
|
||||||
{this.props.ui.progressBarVisible && <LoadingIndicatorBar />}
|
{this.props.ui.progressBarVisible && <LoadingIndicatorBar />}
|
||||||
{this.props.notifications}
|
{this.props.notifications}
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
// @flow
|
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
function getScript() {
|
|
||||||
if (!process.env.GOOGLE_ANALYTICS_ID) return undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
__html: `
|
|
||||||
window.dataLayer = window.dataLayer || [];
|
|
||||||
function gtag(){dataLayer.push(arguments);}
|
|
||||||
gtag('js', new Date());
|
|
||||||
gtag('config', '${process.env.GOOGLE_ANALYTICS_ID}');
|
|
||||||
`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function Analytics() {
|
|
||||||
if (!process.env.GOOGLE_ANALYTICS_ID) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<span>
|
|
||||||
<script
|
|
||||||
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.GOOGLE_ANALYTICS_ID}`}
|
|
||||||
/>
|
|
||||||
<script dangerouslySetInnerHTML={getScript()} />
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Analytics;
|
|
@ -2,7 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import Navigation from './Navigation';
|
import Navigation from './Navigation';
|
||||||
import Analytics from './Analytics';
|
import Analytics from '../../../shared/components/Analytics';
|
||||||
import globalStyles from '../../../shared/styles/globals';
|
import globalStyles from '../../../shared/styles/globals';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
25
shared/components/Analytics.js
Normal file
25
shared/components/Analytics.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// @flow
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
function Analytics() {
|
||||||
|
const id = process.env.GOOGLE_ANALYTICS_ID;
|
||||||
|
if (!id) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
<script src={`https://www.googletagmanager.com/gtag/js?id=${id}`} />
|
||||||
|
<script
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: `
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
gtag('config', '${id}');
|
||||||
|
`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Analytics;
|
@ -14,7 +14,7 @@ const definePlugin = new webpack.DefinePlugin({
|
|||||||
SLACK_KEY: JSON.stringify(process.env.SLACK_KEY),
|
SLACK_KEY: JSON.stringify(process.env.SLACK_KEY),
|
||||||
BASE_URL: JSON.stringify(process.env.URL),
|
BASE_URL: JSON.stringify(process.env.URL),
|
||||||
BUGSNAG_KEY: JSON.stringify(process.env.BUGSNAG_KEY),
|
BUGSNAG_KEY: JSON.stringify(process.env.BUGSNAG_KEY),
|
||||||
DEPLOYMENT: JSON.stringify(process.env.DEPLOYMENT || 'hosted'),
|
DEPLOYMENT: JSON.stringify(process.env.DEPLOYMENT || 'hosted')
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -38,6 +38,7 @@ productionWebpackConfig.plugins.push(
|
|||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env': {
|
||||||
NODE_ENV: JSON.stringify('production'),
|
NODE_ENV: JSON.stringify('production'),
|
||||||
|
GOOGLE_ANALYTICS_ID: JSON.stringify(process.env.GOOGLE_ANALYTICS_ID),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user