Skip to content

Conversation

DanLDU
Copy link
Contributor

@DanLDU DanLDU commented Oct 2, 2025

πŸ”— Linked issue

Global gtag function not exposed when using GTM via useScriptGoogleTagManager (#523)

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Expose globally the gtag function on the Google Tag Manager Script, useful for consent updates.

Copy link

vercel bot commented Oct 2, 2025

Someone is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Oct 2, 2025

Open in StackBlitz

npm i https://pkg.pr.new/nuxt/scripts/@nuxt/scripts@524

commit: 5ca73a3

@harlan-zw
Copy link
Collaborator

@huang-julien I guess we had this at some point and then removed it.

I'm fine with adding it back even if it does end up conflicting with different GTM scripts; what do you think?

@harlan-zw harlan-zw changed the title feat: gtm gtag function global access fix(gtm): expose gtag globally Oct 5, 2025
@huang-julien
Copy link
Member

the reason we removed it was if there's multiple google tag managers. one gtag would overwrite another

@harlan-zw
Copy link
Collaborator

harlan-zw commented Oct 7, 2025

This PR seems to go against the documented usage of scripts, which is to rely on the .proxy accessor or using the onLoaded() hook.

Given that gtag is essentially a queue function, though, and doesn't fail if adblockers block GTM then I think we should just merge it as there may be some dependency on it being available on the window accessor in other third-party code.

@harlan-zw harlan-zw merged commit d43dffa into nuxt:main Oct 7, 2025
3 of 5 checks passed
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 this pull request may close these issues.

3 participants