Skip to content

Test analytics consent gating before any Google request - #279

Draft
manav4u wants to merge 1 commit into
mainfrom
test/analytics-consent
Draft

manav4u wants to merge 1 commit into
mainfrom
test/analytics-consent

Conversation

@manav4u

@manav4u manav4u commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Adds regression tests for lib/analytics.ts, which is privacy-critical and previously needed two consent fixes (fix/analytics-after-accept-only, fix/analytics-gtag-arguments) but had no test coverage.

The tests shim the browser globals the module touches (localStorage, window, document) and lock in:

  • Consent Mode v2 default is pushed all-denied before any choice, and no gtag script is requested before acceptance.
  • Reject updates consent to denied and never loads the Google script.
  • Accept updates consent to granted and appends exactly one gtag/js?id=G-... script, even on repeat acceptance.
  • A stored acceptance from a previous visit starts analytics on init.
  • The consent reader returns null for garbage values and blocked storage instead of treating them as a choice.

Full suite: 119/119 passing (114 existing + 5 new); typecheck clean. Test-only change, no production code touched.

Co-authored-by: MaxwithU19 156198184+MaxwithU19@users.noreply.github.com

Co-authored-by: MaxwithU19 <156198184+MaxwithU19@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant