Skip to content

fix(*): adding google tag manager artifacts for tracking - #492

Merged
ChronosSF merged 1 commit into
vnextfrom
sstoychev/adding-gtm
Aug 17, 2026
Merged

fix(*): adding google tag manager artifacts for tracking#492
ChronosSF merged 1 commit into
vnextfrom
sstoychev/adding-gtm

Conversation

@ChronosSF

Copy link
Copy Markdown
Member

This is how GTM should be implemented according to @dianj

  1. Paste this code as high in the of the page as possible:
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '[https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);](https://www.googletagmanager.com/gtm.js?id=%27+i+dl;f.parentNode.insertBefore(j,f);) })(window,document,'script','dataLayer','GTM-T65CF7');</script>
  1. Paste this code immediately after the opening tag:

<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T65CF7"
height="0" width="0" style="display:none;visibility:hidden"></iframe>

@ChronosSF
ChronosSF requested a review from viktorkombov August 13, 2026 13:45
@ChronosSF ChronosSF added the ❌ status: awaiting-test PRs awaiting manual verification label Aug 13, 2026
@ChronosSF
ChronosSF requested a lite review from Copilot August 13, 2026 13:46

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

Implements Google Tag Manager (GTM) tracking for the docs site by injecting the GTM <script> into the document <head> and the required <noscript> iframe immediately after the opening <body> tag, with container ID resolution based on env overrides and build mode.

Changes:

  • Inject GTM <script> into the generated <head> entries for the site.
  • Add middleware HTML rewriting to inject the GTM <noscript> iframe after <body>.
  • Introduce getGtmContainerId() with env/env-json/default resolution logic.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/middleware.ts Rewrites HTML responses to inject the GTM <noscript> iframe after <body>.
src/lib/platform-context.ts Adds getGtmContainerId() and per-mode default container IDs.
src/integration.ts Adds GTM bootstrap <script> to the site head entries early in <head>.
Suppressed comments (1)

src/middleware.ts:15

  • response.text() consumes the response body; if the HTML does not contain a tag you return the original response after its body has been read, which can result in an empty body or a runtime error. Clone the response (or read from a clone) before calling .text() so the original can still be returned unchanged.
    const html = await response.text();
    if (!/<body[^>]*>/i.test(html)) return response;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/middleware.ts
@viktorkombov viktorkombov added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification labels Aug 13, 2026
@viktorkombov viktorkombov added ✅ status: verified Applies to PRs that have passed manual verification and removed 💥 status: in-test PRs currently being tested labels Aug 13, 2026
@ChronosSF
ChronosSF force-pushed the sstoychev/adding-gtm branch 2 times, most recently from 001f5ff to b179ea3 Compare August 17, 2026 11:27
@ChronosSF
ChronosSF merged commit f6672a6 into vnext Aug 17, 2026
13 checks passed
@ChronosSF
ChronosSF deleted the sstoychev/adding-gtm branch August 17, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ status: verified Applies to PRs that have passed manual verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants