* refactor: 🔧 del unnecessary children type Change-Id: I3dea5e07f5401bdbdd168eb959fe361c57784167 * feat: 💄 eslint Change-Id: Ie173adeca9e3112d8cdfc1f85964332105dcb424 * feat: 🔧 add css type Change-Id: I8850c4d09b152f4d9c4d98e6eebca58bd9eecd37 * fix: 💄 ci lint Change-Id: I69ff89c7a30e2bdcd26475ec83f3f5ec143121b6
42 lines
935 B
TypeScript
42 lines
935 B
TypeScript
/* global ga */
|
|
import * as React from "react";
|
|
import env from "~/env";
|
|
|
|
export default class Analytics extends React.Component {
|
|
componentDidMount() {
|
|
if (!env.GOOGLE_ANALYTICS_ID) {
|
|
return;
|
|
}
|
|
|
|
// standard Google Analytics script
|
|
window.ga =
|
|
window.ga ||
|
|
function (...args) {
|
|
(ga.q = ga.q || []).push(args);
|
|
};
|
|
|
|
ga.l = +new Date();
|
|
ga("create", 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;
|
|
|
|
// Track PWA install event
|
|
window.addEventListener("appinstalled", () => {
|
|
ga("send", "event", "pwa", "install");
|
|
});
|
|
|
|
if (document.body) {
|
|
document.body.appendChild(script);
|
|
}
|
|
}
|
|
|
|
render() {
|
|
return this.props.children || null;
|
|
}
|
|
}
|