Fix gtag queue to use arguments object for proper replay - #68
Merged
Conversation
Google Analytics reported the tag as detected on the Pages site but never recorded any events. initGoogleAnalytics installed an arrow-function gtag that pushed a rest-parameter array onto window.dataLayer. gtag.js only replays queued entries that are the arguments object; plain arrays are ignored, so the js and config commands and every subsequent event were dropped after the tag script loaded. Nothing was ever sent to /g/collect. - web/telemetry.mjs: replace the arrow function with makeGtagQueue, a named function that pushes its arguments object, matching the canonical gtag snippet. The existing window.gtag reuse path and the rest of the GA setup are unchanged. - scripts/telemetry-test.mjs: assert every queued dataLayer entry is an arguments object, so a rewrite back to an array push fails the suite, and spread the config command before comparing it against the expected argument list. - docs/telemetry.md: record the queue-shape requirement and the detected-but- silent failure mode it causes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DLfiWrE8kmpqMM913UPHCr
There was a problem hiding this comment.
🟢 Ready to approve
The change is narrowly scoped, aligns the queue with gtag.js’s expected replay shape, and includes matching test and documentation updates.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR fixes the Google Analytics gtag bootstrap queue in web/telemetry.mjs so queued commands are pushed to window.dataLayer as the arguments object (matching what gtag.js replays), rather than as plain arrays that can be ignored during replay.
Changes:
- Replaced the inline
(...args) => dataLayer.push(args)queue with amakeGtagQueue(win)implementation that pushesarguments. - Updated the telemetry smoke test to assert queued
dataLayerentries areArgumentsobjects and to compare content by spreading into arrays. - Documented the
gtagqueue contract and why theargumentsshape matters for replay.
File summaries
| File | Description |
|---|---|
| web/telemetry.mjs | Uses a dedicated makeGtagQueue() that pushes arguments objects to dataLayer for gtag.js replay compatibility. |
| scripts/telemetry-test.mjs | Strengthens assertions to validate dataLayer entry shape and adapts comparisons for Arguments objects. |
| docs/telemetry.md | Adds documentation describing the gtag queue contract and replay implications. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
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.
Summary
Fixed the gtag queue implementation to push the
argumentsobject instead of plain arrays. This ensures compatibility withgtag.js's command replay mechanism, which only processes queued entries that are theargumentsobject.Key Changes
makeGtagQueue()function that properly captures and pushes theargumentsobject todataLayerargumentsobjects, not plain arraysargumentsobjects to arrays for comparison using spread operatorargumentsobject shape mattersImplementation Details
The
gtag.jslibrary has specific behavior: it only replays commands fromdataLayerif they were pushed as theargumentsobject. Plain arrays are ignored during replay, which would cause the analytics tag to load without sending any hits. This change ensures the queue is shaped correctly for proper command replay whengtag.jsloads.https://claude.ai/code/session_01DLfiWrE8kmpqMM913UPHCr