From e91f7bcef99c29cf194f9643fa474b2a8c5e4490 Mon Sep 17 00:00:00 2001 From: Jaewook Ahn Date: Wed, 26 Aug 2020 02:04:48 +0900 Subject: [PATCH] Improve: ignore analytics tracking in development --- public/analytics.js | 4 ---- src/index.tsx | 13 ++++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/public/analytics.js b/public/analytics.js index bcc06a0..ebb6b51 100644 --- a/public/analytics.js +++ b/public/analytics.js @@ -2,7 +2,3 @@ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); - -ga("create", "UA-108816190-2", "auto"); -ga("set", "checkProtocolTask", null); -ga("send", "pageview", "/"); diff --git a/src/index.tsx b/src/index.tsx index cc3aaae..5339c69 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,14 +1,25 @@ import React from "react"; import { render } from "react-dom"; import { App } from "./App"; -import { getRuntime } from "./utils"; +import { getRuntime, getEnv } from "./utils"; import { AddressManager } from "./AddressManager"; import { SettingsManager, Settings, DEFAULT_SETTINGS } from "./SettingsManager"; +// inject NODE_ENV variable into window object window.__ENV__ = { NODE_ENV: process.env.REACT_APP_ENV as string, }; +// initialize google analytics only in production +if (getEnv() === "production") { + window.ga("create", "UA-108816190-2", "auto"); + window.ga("set", "checkProtocolTask", null); + window.ga("send", "pageview", "/"); +} else { + console.info("Google Analytics disabled because runtime does not running in production."); + window.ga = function() {}; +} + let settings = null; if (getRuntime() === "extension") {