-
Notifications
You must be signed in to change notification settings - Fork 28
fix: gtag is not defined #792
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
base: main
Are you sure you want to change the base?
fix: gtag is not defined #792
Conversation
✅ Deploy Preview for node-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for vue-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for qwik-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for system-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for angular-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for solid-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for svelte-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for graphql-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for react-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for deno-framework-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Add gtag to global var
Content addition
Bug fix
Behavior change
Summary of change
Fixed
Uncaught ReferenceError: gtag is not definederror by ensuringgtagis properly attached to the globalwindowobject and adding safety checks before calling it. Thetrack()function inanalytics-utils.tsnow verifies thatwindow.gtagexists before attempting to call it, preventing runtime errors when the Google Analytics script hasn't loaded yet or in development mode.Checklist
This fix resolves #
The changes follow the contributing guidelines
I have verified the fix works and introduces no further errors
Changes Made
packages/system/src/util/analytics-utils.ts: Added safety checks to verifywindow.gtagexists before calling it, preventingReferenceErrorwhen gtag is not available.packages/site/src/layouts/base.astro: Addedwindow.gtag = gtag;to explicitly attach the gtag function to the global window object in the inline script.packages/landing-site/src/pages/index.astro: Addedwindow.gtag = gtag;to explicitly attach the gtag function to the global window object in the inline script.