Adding Google Tag Manager to Nextjs Using Script
Unanswered
Mossyrose gall wasp posted this in #help-forum
Mossyrose gall waspOP
Hello, I am trying to add gtm id to my nextjs project i want to sure about that i am doing that right way.
Here is my _document.js:
I also add _app.js file those:
But when i navigato to google tag assistant there is not shown any scripts. Did i miss something?
Thanks in advance!
Here is my _document.js:
<Html lang="en">
<Head>
<Script
id="gtm-script"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `(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','GTM-XXXXXXX');`,
}}
/>
<body>
<Main />
<NextScript />
<noscript
dangerouslySetInnerHTML={{
__html:
'<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"height="0" width="0" style="display:none;visibility:hidden"></iframe>',
}}
/>
</body>
</Html>I also add _app.js file those:
<Script id="gtm-script" strategy="afterInteractive">
{`
(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','GTM-XXXXXX');
`}
</Script>But when i navigato to google tag assistant there is not shown any scripts. Did i miss something?
Thanks in advance!