Repository navigation
Load gtag.js only after the visitor accepts - #218
Merged
Merged
Conversation
|
🚀 Preview deployed for |
|
🛠️ API preview deployed for |
korya
marked this pull request as ready for review
September 18, 2026 19:16
korya
force-pushed
the
korya-fix-consent-before-tag
branch
from
September 18, 2026 19:22
c746bdf to
820d434
Compare
The privacy policy says a visitor who declines is not reported to Google: "Until you accept, no analytics cookies are set and no measurement data is collected." Advanced consent mode contradicts that. It loads the tag for everyone with storage denied, and those cookieless pings still carry page URL, referrer, device and IP to Google — for people who said no. The contradiction was dormant only because the tag never worked at all; the previous commit would have made it live. Previously the tag loaded on every visit to the production host and `grantConsent()` lifted the denial on accept. Now nothing Google-bound is requested until the visitor accepts, and accepting loads the tag with the full batch — denial, grant, `js`, `config` — which measures identically: `gcs=G101`, ad storage still denied. This matches qr-code-gen.frontsail.app, whose implementation already worked this way. What we give up is Google's behavioural modelling of non-consenting visitors, which needs 1,000 denied events per day for 7 days before it engages. The demo is orders of magnitude below that, so those pings bought nothing and cost a promise. `bootCommands` and `loadTag` lose their `stored` parameter: both are now reached only after consent, so the grant is unconditional and `grantConsent` is gone. Two unit tests went with it — "an unanswered visitor is never silently granted" and "a returning refuser stays denied with no update" asserted branches that no longer exist. The guarantee they approximated is now checked where it is observable, in e2e: a visitor who declines or ignores the banner produces no request to Google at all, on that visit or the next. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
korya
force-pushed
the
korya-fix-consent-before-tag
branch
from
September 18, 2026 19:32
820d434 to
3da50cd
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.
Problem
The demo now reports visitors to Google who pressed Decline. Since #216 made the GA4 tag work, it runs in Google's advanced consent mode: loaded for everyone with storage denied, sending cookieless pings that still carry page URL, referrer, device and IP — for people who said no.
The privacy policy promises the opposite, in as many words:
The contradiction was dormant while the tag was inert. It went live when #216 merged, which is why this follows immediately behind it.
Solution
Load gtag.js only once the visitor accepts, so nothing Google-bound is requested before that — not the collector, and not the script itself.
Before / after, for a visitor who declines:
The accepting path is unchanged in substance: the same batch is queued — denial default → grant →
js→config— and then the tag is fetched, measuring identically atgcs=G101, with ad storage still denied for someone who only agreed to analytics. I verified that ordering end to end in a live browser before writing the change. This also matches qr-code-gen.frontsail.app, whose implementation already worked this way.What we give up is Google's behavioural modelling of non-consenting visitors, which needs 1,000
analytics_storage='denied'events per day for 7 days before it engages. The demo is orders of magnitude below that, so those pings bought nothing and cost a promise.bootCommandsandloadTaglose theirstoredparameter — both are now reached only after consent — so the grant is unconditional andgrantConsentis gone. Two unit tests went with it: "an unanswered visitor is never silently granted" and "a returning refuser stays denied with no update" asserted branches that no longer exist. The guarantee they approximated is now checked where it is observable: e2e asserts that a decliner, and a visitor who ignores the banner, produce no Google-bound request at all — on that visit or the next.Verified by breaking the code it guards: reverting the gate in
main.tsfails exactly those two silence tests and nothing else.No visual change — the banner, its copy, and the stored-choice behaviour are untouched.
Other Changes
Related:
argumentsso GA4 actually records #216🤖 Generated with Claude Code