fix(*): adding google tag manager artifacts for tracking - #492
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 originalresponseafter 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.
viktorkombov
approved these changes
Aug 13, 2026
ChronosSF
force-pushed
the
sstoychev/adding-gtm
branch
2 times, most recently
from
August 17, 2026 11:27
001f5ff to
b179ea3
Compare
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.
This is how GTM should be implemented according to @dianj
- 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><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T65CF7"
height="0" width="0" style="display:none;visibility:hidden"></iframe>