diff --git a/pages/_document.tsx b/pages/_document.tsx index 8f176b0..2bc1952 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -8,15 +8,19 @@ interface DocumentProps { } function trackingScript() { - window["dataLayer"] = window["dataLayer"] || []; + // @ts-ignore + if (window.dataLayer) return; + // @ts-ignore + window.dataLayer = window.dataLayer || []; function gtag() { - window["dataLayer"].push(arguments); + // @ts-ignore + window.dataLayer.push(arguments); } // @ts-ignore gtag("js", new Date()); // @ts-ignore - gtag("config", "UA-60624235-5"); + gtag("config", "UA-60624235-8"); } export default class MyDocument extends Document { @@ -31,10 +35,6 @@ export default class MyDocument extends Document { }; } - componentDidMount(): void { - trackingScript(); - } - render() { const { css, hydrationScript } = this.props; @@ -56,8 +56,11 @@ export default class MyDocument extends Document { );