Skip to content

fix(gtm): improving gtm integration - #504

Open
ChronosSF wants to merge 7 commits into
vnextfrom
sstoychev/improve-gtm-implementation
Open

fix(gtm): improving gtm integration#504
ChronosSF wants to merge 7 commits into
vnextfrom
sstoychev/improve-gtm-implementation

Conversation

@ChronosSF

Copy link
Copy Markdown
Member
  1. 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.

  2. The noscript fallback rendered in the middle of the page. It sat inside main, between the breadcrumb and the h1, 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.

  3. 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.

@ChronosSF ChronosSF added the ❌ status: awaiting-test PRs awaiting manual verification label Aug 18, 2026
@ChronosSF

ChronosSF commented Aug 18, 2026

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@viktorkombov viktorkombov added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification labels Sep 8, 2026
@viktorkombov

Copy link
Copy Markdown
Contributor

Tested locally, and the SPA bridge looks good: one page_view_spa event per navigation, with the correct URL and title and no duplicates.

Could you please help clarify two points?

  1. How will docs restore saved consent choices and send consent updates? I can see the denied defaults, but couldn’t find the integration with the main site’s consent controller.

  2. Is there an accompanying GTM configuration update for page_view_spa? The published container I checked listens to trackSPAPageview, so it would be helpful to confirm that the new event will trigger the intended Analytics tags.

Тhanks!

@ChronosSF

Copy link
Copy Markdown
Member Author

Tested locally, and the SPA bridge looks good: one page_view_spa event per navigation, with the correct URL and title and no duplicates.

Could you please help clarify two points?

  1. How will docs restore saved consent choices and send consent updates? I can see the denied defaults, but couldn’t find the integration with the main site’s consent controller.
  2. Is there an accompanying GTM configuration update for page_view_spa? The published container I checked listens to trackSPAPageview, so it would be helpful to confirm that the new event will trigger the intended Analytics tags.

Тhanks!

  1. Fixed with the latest commit. For first time visitors , they won't get the consent form though, this requires for it to be available in /navigation markup with the consent script obtainable from somewhere (we strip the scripts atm). I am separately talking to the web team and logged an issue for them to include these. We'll probably need a separate pr to completely solve the consent issue.
  2. trackSPAPageview. I'd missed that trigger, thanks. The bridge now pushes trackSPAPageview instead of page_view_spa, so it hits the existing trigger (G-8SESBBYZVB with the productCode/resourceType/leadType user properties, and G-PN11HXDV6X) with no container change. It still carries page_path/page_location/page_title for Preview debugging; the tags use the built-in Page URL and Title.

@ChronosSF

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💥 status: in-test PRs currently being tested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants