fix(gtm): improving gtm integration - #504
Open
ChronosSF wants to merge 1 commit into
Open
Conversation
Member
Author
|
@viktorkombov , @dobromirts , obv agent created. When I was merging the original gtm implementation to vnext, copilot had a review pointing to a performance warning which it then fixed in a way that changed where the tags are rendered incorrectly. This additional fix should make things as they should be. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds consent-aware GTM initialization, SPA navigation tracking, and correctly positioned fallback markup.
Changes:
- Initializes Consent Mode before loading GTM.
- Tracks Astro client-side navigations.
- Injects the GTM fallback immediately after
<body>during builds.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/integration.ts |
Adds consent, SPA tracking, and post-build fallback injection. |
src/components/GtmNoscript.astro |
Removes the obsolete component fallback. |
src/routes/[...slug].astro |
Removes in-content fallback rendering. |
src/pages/[...slug].astro |
Removes in-content fallback rendering. |
src/pages/index.astro |
Removes in-content fallback rendering. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Consent Mode defaults were missing. The main site sets all seven storage types to denied with wait_for_update: 500 (plus the user_id push) before loading GTM; docs pages had no consent code at all. Both share container GTM-T65CF7, so docs traffic was entering the same container ungated — a compliance risk, and it made docs sessions non-comparable with the rest of the site. The defaults are now the first script in , ahead of the loader, matching the main site block.
The noscript fallback rendered in the middle of the page. It sat inside
main, between the breadcrumb and theh1, because DocsLayout comes from the published igniteui-astro-components package and exposes no body-top slot — a component can only render into the content region, which is also the Pagefind-indexed body. It's now injected immediately after by a post-build HTML rewrite (createGtmNoscriptIntegration), following the existing createBasePrependIntegration pattern. A middleware rewrite was the alternative, but that reintroduces the response buffering removed in Render GTM fallback without buffering HTML responses #493.Client-side navigation was untracked. DocsLayout renders , so topic-to-topic navigation is a pushState swap: gtm.js runs only on the initial hard load, and the published container has no history-change trigger. Every navigation after the first was invisible to any GTM tag bound to All Pages. A bridge now pushes page_view_spa (page_path, page_location, page_title) on astro:page-load, skipping the initial fire so it doesn't double-count.