[experimental] nextScriptWorkers doesn't work with GTM
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37 PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64
Binaries:
Node: 16.13.2
npm: 8.1.2
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.1.5
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
Chrome 100.0.4896.75
How are you deploying your application? (if relevant)
next dev
Describe the Bug
I’m trying to use worker strategy to load third party scripts, but it doesn’t work properly. I follow the docs and set nextScriptWorkers: true
flag in next.config.js
, install partytown when requested, and set by third-party script strategy to worker
, but it seems doesn’t work.
<Script
strategy="worker"
id="gtm"
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+'>m_auth=${process.env.NEXT_PUBLIC_GTM_AUTH}>m_preview=${process.env.NEXT_PUBLIC_GTM_PREVIEW}>m_cookies_win=x';f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${process.env.NEXT_PUBLIC_GTM_ID}');`,
}}
/>
Expected Behavior
Load third party scripts
To Reproduce
- Set
nextScriptWorkers: true
flag - Set strategy to
worker
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
Integrate Google Tag Manager with Next.js - Morgan Feeney
How to setup Next.js to work ith Google Tag Manager (GTM). ... tracking page views the existing triggers/tag events didn't work as expected....
Read more >Houssein Djirdeh on Twitter: "Friendly reminder: there's an ...
Friendly reminder: there's an experimental Next.js flag that lets you to relocate third-party scripts to a web worker using Partytown. We need more...
Read more >Basic Features: Handling Scripts - Next.js
Optimize your third-party scripts with the built-in `next/script` component. ... worker : (experimental) Load the script in a web worker.
Read more >next.js - How to set up Google Analytics through Google Tag ...
Now you are all set to use Google Tag Manager in your next-js app. You should only proceed to handle pageview and other...
Read more >Using GTM with a Content Security Policy (CSP) and impress ...
I'm Dumky, analytics engineer. I've spent the first half of my working life in web analytics turning Google Tag Manager (GTM) inside out....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I’m having the same issue. I can’t 100% say that my issue is caused for the same reason, but I’m also trying to load GTM in the same way as the above. To add some extra information though, I see this console error:
This is after I had the following in my
__app.tsx
:Just incase this helps, here’s the
next info
output for my setup:This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.