Skip to content

fix(analytics): fail closed when consent is missing or storage throws - #6

Merged
SH20RAJ merged 1 commit into
SopKit:mainfrom
playlikeboy:fix/analytics-consent-fail-closed
Nov 27, 2026
Merged

SH20RAJ merged 1 commit into
SopKit:mainfrom
playlikeboy:fix/analytics-consent-fail-closed

Conversation

@playlikeboy

Copy link
Copy Markdown
Contributor

Summary

  • Fix isAnalyticsAllowed() in src/lib/analytics.ts to return false inside the catch block when localStorage is unavailable or throws (e.g. Safari private mode / sandboxed iframes), rather than falling through to return true.
  • Update tests/unit/analytics.test.ts to mock localStorage consent explicitly in beforeEach and add regression coverage for missing consent, denied consent, window.__sopkit_analytics_disabled, throwing localStorage, and suppressed dataLayer writes.

Verification

  • bun run test:arch (211 passed, 0 failed)
  • bun run typecheck (exit code 0)

SH20RAJ commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. Failing closed when consent storage is unavailable is the safer analytics behavior, and the added cases cover missing/denied consent, the disable flag, and storage exceptions. The PR description records the architecture test suite and typecheck. GitHub currently shows no CI check runs on this head.

@SH20RAJ
SH20RAJ merged commit 348486a into SopKit:main Nov 27, 2026
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.

2 participants