Restore analytics bootstrapping in Next apps#963
Merged
PavelMakarchuk merged 1 commit intomainfrom Apr 15, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
This PR correctly restores analytics bootstrapping in the Next.js apps. The implementation is solid and matches the legacy Vite app pattern:
What's correct:
- ✅ GA4 measurement ID (G-2YHG89FY0N) matches the legacy HTML files
- ✅ Uses Next.js Script component with proper strategy (afterInteractive)
- ✅ Assigns window.gtag globally for downstream code compatibility
- ✅ Analytics and SpeedInsights components properly mounted in body
- ✅ Dependencies (@vercel/analytics, @vercel/speed-insights) available in root package.json
- ✅ Both calculator-app and website layouts updated consistently
Verification:
The legacy Vite apps (app/calculator.html, app/website.html) have the same GA4 bootstrap script, and the main entry files (main.calculator.tsx, main.website.tsx) mount Analytics/SpeedInsights components. This PR correctly ports that pattern to the Next.js layouts.
No issues found. The implementation will restore window.gtag and analytics tracking on migrated routes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restore GA4 and Vercel analytics bootstrapping in the Next.js website and calculator app layouts.
Root cause
The legacy Vite apps loaded GA and mounted Vercel Analytics, but the migrated Next app layouts did not. That left
window.gtagundefined on migrated routes and caused analytics to drop sharply once traffic shifted to those apps.Changes
gtag.jsinwebsite/src/app/layout.tsxwindow.dataLayerandwindow.gtaginwebsite/src/app/layout.tsx@vercel/analyticsand@vercel/speed-insightsinwebsite/src/app/layout.tsxgtag.jsincalculator-app/src/app/layout.tsxwindow.dataLayerandwindow.gtagincalculator-app/src/app/layout.tsx@vercel/analyticsand@vercel/speed-insightsincalculator-app/src/app/layout.tsxVerification
bun run devhttp://localhost:3002/usincludes GA4 bootstrap and Vercel analytics clientshttp://localhost:3002/us/pe84includes GA4 bootstrap and the migratedAppClientroute bundle used fortool_engagedhttp://localhost:3003/us/simulationsincludes GA4 bootstrap and Vercel analytics clientsNotes
No QueryClient set, use QueryClientProvider to set one