fix(ga4): fix gtag.js dataLayer integration and consent defaults#11
Merged
fix(ga4): fix gtag.js dataLayer integration and consent defaults#11
Conversation
Replace simulatedGA4 no-op with the real @junctionjs/destination-ga4 package. GA4 is conditionally enabled via NEXT_PUBLIC_GA4_MEASUREMENT_ID env var. When the env var is absent, the demo works as before (demo sink only + simulated vendors). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two bugs fixed:
1. gtag stub used arrow function with rest params, pushing Arrays to
dataLayer. gtag.js silently ignores array entries — it expects the
Arguments object. Switched to `function() { dataLayer.push(arguments) }`
matching Google's official snippet.
2. When consentMode is enabled, gtag("consent", "default", {...}) must
fire before gtag("config", ...) so gtag.js knows consent mode is
active. Without this, consent state was never communicated to Google.
Arrow functions don't have their own `arguments` object, which breaks the gtag dataLayer integration. Added biome-ignore for both useArrowFunction and noArguments rules.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
dataLayer. gtag.js silently ignores array entries and expects theargumentsobject. Switched to a named function declaration matching Google's official snippet.gtag("consent", "default", {...})now fires beforegtag("config", ...)whenconsentMode: true, so gtag.js knows consent mode is active.@junctionjs/destination-ga4package, gated onNEXT_PUBLIC_GA4_MEASUREMENT_IDenv var.Test plan
<head>collect?v=2network requests fire after granting consentpage_view,view_item,select_item, etc.)🤖 Generated with Claude Code