Skip to content

fix(gtm): improving gtm integration - #504

Open
ChronosSF wants to merge 1 commit into
vnextfrom
sstoychev/improve-gtm-implementation
Open

fix(gtm): improving gtm integration#504
ChronosSF wants to merge 1 commit 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.

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

Labels

❌ status: awaiting-test PRs awaiting manual verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants