From 09614d1f732cc191ba0e22a3feef8f8946c4c114 Mon Sep 17 00:00:00 2001 From: imhson Date: Fri, 18 Aug 2023 10:18:13 +0700 Subject: [PATCH] update gtm --- public/config.json | 3 +- src/pages/_app.tsx | 16 +++++++++++ src/pages/_document.tsx | 28 ------------------- .../chapter/[chapterNumber]/chapter.tsx | 3 -- .../chapter/[chapterNumber]/with-api.tsx | 4 --- 5 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 src/pages/_document.tsx diff --git a/public/config.json b/public/config.json index 253f7a79..f19c7a70 100644 --- a/public/config.json +++ b/public/config.json @@ -24,5 +24,6 @@ }, "REDIRECT_URL": "http://localhost:3000/", "REST_API_URL": "https://api.staging.punkga.me", - "IN_MAINTENANCE_MODE": false + "IN_MAINTENANCE_MODE": false, + "GTM_ID": "GTM-PF4MH72V" } diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 624d84e5..dc00621f 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -82,6 +82,22 @@ const App = ({ Component, pageProps }: AppProps) => { setEmailErrorMsg('') }, [email]) + useEffect(() => { + console.log(getConfig()) + const scriptElement = document.createElement('script') + scriptElement.innerHTML = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= + 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); + })(window,document,'script','dataLayer','${getConfig()['GTM_ID']}');` + document.head.append(scriptElement) + const noscriptElement = document.createElement('noscript') + noscriptElement.innerHTML = `` + document.body.append(noscriptElement) + }, []) + if (isSettingUp) { return <> } diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx deleted file mode 100644 index ce3ad284..00000000 --- a/src/pages/_document.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { Html, Head, Main, NextScript } from 'next/document' - -export default function Document() { - return ( - - -