Skip to content

GoogleTagManager is not properly loading and executing Tags loaded by it. #77946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tskorupka opened this issue Apr 8, 2025 · 1 comment · May be fixed by #77947
Open

GoogleTagManager is not properly loading and executing Tags loaded by it. #77946

tskorupka opened this issue Apr 8, 2025 · 1 comment · May be fixed by #77947

Comments

@tskorupka
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/kind-wildflower-y8zk4n?workspaceId=ws_5dafRhSwd3kbzr7DasDeFF

To Reproduce

  1. Start the application in the development mode (code sandbox)
  2. Open homepage and see alert Main GTM-...
  3. Click Not working, and see no alert.
  4. Click Back to go to homepage.
  5. Click Working, and see alert.

Current vs. Expected behavior

Currently GoogleTagManager ids are not unique per Component, since that the scripts loaded by GTM when navigating in browser between different pages are not being executed.

Expectation is that they will be executed once loaded.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4242
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.3.0-canary.44 // Latest available version is detected (15.3.0-canary.44).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

Other (Deployed), next dev (local), next start (local)

Additional context

I tested this locally with newest stable next 15.2.4.

I also have done some digging since this feature if vital for my company, to resolve it. The fix is also attached within the code sandbox project.

Basically if we provide simple fix with appending gtmId into the elements rendered by GoogleTagManager, this should solve the issue.

tskorupka added a commit to tskorupka/next.js that referenced this issue Apr 8, 2025
…n GTM is defined multiple times and scripts are not being fired, when navigating between pages vercel#77946
@tskorupka
Copy link
Author

PR was added to highlight changes required to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant