From 17c787a74c94ca73783c79e2813accf293424706 Mon Sep 17 00:00:00 2001 From: Jaewook Ahn Date: Tue, 9 Aug 2022 22:21:56 +0900 Subject: [PATCH] Fix gtag setup --- src/index.tsx | 5 +++++ src/react-app-env.d.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 3709d38..b079361 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,11 +18,16 @@ window.__ENV__ = { NODE_ENV: process.env.REACT_APP_ENV as string, }; +window.dataLayer = window.dataLayer || []; if (isProduction()) { + window.gtag = function(...args: any[]) { + window.dataLayer.push(args); + }; window.gtag("config", "G-NJFP4YL0X3", { allow_google_signals: false, allow_ad_personalization_signals: false, }); + window.gtag("js", new Date()); Sentry.init({ dsn: "https://6b96accd47ff467da8394a51da93d909@o415139.ingest.sentry.io/5305794" }); } else { console.info("Google Analytics disabled because runtime does not running in production."); diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index 07eb038..af95072 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -4,4 +4,5 @@ interface Window { NODE_ENV: string; }; gtag: Function; + dataLayer: Array; }