From 0ca0d17eadcd0af4f7356f420b58cf71cf73da43 Mon Sep 17 00:00:00 2001 From: Ritesh Kumar Date: Mon, 22 Jul 2019 15:34:36 +0530 Subject: [PATCH] chore(analytics): disable google analytics in dev mode (#121) --- pages/_app.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pages/_app.tsx b/pages/_app.tsx index 016e062..5746a71 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -7,14 +7,11 @@ import "@styles/main.css"; import NProgress from "nprogress"; import { useRouter } from "next/router"; import { activeRouteData } from "@utils/routes"; -import { Head } from "next/document"; let reactGa; -if (IN_BROWSER) { +if (IN_BROWSER && !IS_DEV) { reactGa = require("react-ga"); - reactGa.initialize("UA-60624235-8", { - debug: IS_DEV - }); + reactGa.initialize("UA-60624235-8"); } const logo = ( @@ -64,13 +61,13 @@ export default function App({ Component, pageProps }) { const router = useRouter(); useEffect(() => { - reactGa.pageview(router.pathname); + reactGa && reactGa.pageview(router.pathname); const startProgress = () => NProgress.start(); let timer; const stopProgress = pathname => { - reactGa.pageview(pathname); + reactGa && reactGa.pageview(pathname); clearTimeout(timer); NProgress.done(); };