Repository navigation
Server-render the GTM container snippet - #935
Closed
thostetler wants to merge 1 commit into
Closed
thostetler wants to merge 1 commit into
thostetler wants to merge 1 commit into
Conversation
GoogleTagManager rendered inside <Layout> using next/script at the default afterInteractive strategy, which only runs client-side in the pages router — it wasn't in server HTML and loaded at the end of body after hydration. GTM flagged this as "tag not placed correctly" on / and /abs/* pages. Inlines Google's snippet as the first child of <Head> in _document, gated on NEXT_PUBLIC_GTM_ID being set. sendGTMEvent is unaffected; it only touches window.dataLayer.
Bundle sizeShared by all pages: 624.6 kB (-0.0 kB) ⚪ No route changed by more than 1 kB. ✅ First load = polyfills + shared |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #935 +/- ##
========================================
+ Coverage 67.9% 67.9% +0.1%
========================================
Files 379 378 -1
Lines 44188 44081 -107
Branches 2380 2378 -2
========================================
- Hits 29974 29930 -44
+ Misses 14165 14103 -62
+ Partials 49 48 -1
🚀 New features to boost your workflow:
|
Member
Author
|
Folded into #934 — the GTM placement fix and the user id hook are being tested and shipped together. |
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.
GoogleTagManager was rendered inside using next/script at the default
afterInteractive strategy, which is client-only in the pages router. The
container snippet was missing from server HTML and only appeared at the end of
body after hydration, which GTM's console flagged as "tag not placed correctly"
across / and /abs/* URLs.