-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Labels
enhancementNew feature or requestNew feature or request
Description
π Your use case
When using the useScriptGoogleTagManager composable from the nuxt-scripts module in a Nuxt 4 project, the gtag function is not exposed globally (window.gtag remains undefined), even after the GTM script has loaded.
This prevents any manual use of gtag(), which is essential for features like dynamic consent updates, event tracking, and Google Consent Mode compliance.
π The solution you'd like
Once the GTM script has loaded, window.gtag should be available globally. This allows developers to:
- Update consent dynamically (gtag('consent', 'update', {...}))
- Track custom events manually
- Integrate with third-party libraries that rely on gtag() being present
This is standard behavior when the GTM script is loaded manually or via traditional integrations like @nuxtjs/gtm.
π Alternatives you've considered
// google-tag-manager.ts
Inside clientInit
Assign gtag function to window for global access:
(window as any).gtag = gtag;
or
βΉοΈ Additional info
Versions:
- Nuxt 4.1.2
- Nuxt Scripts 0.12.1
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request