This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/components/Analytics.js
2018-11-19 21:28:15 -08:00

36 lines
814 B
JavaScript

// @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('set', { dimension1: 'true' });
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;
}
}