Skip to content

Feat/analytics consent and instrumentation - #1494

Merged
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
Opulencechuks:feat/analytics-consent-and-instrumentation
Nov 26, 2026
Merged

greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
Opulencechuks:feat/analytics-consent-and-instrumentation

Conversation

@Opulencechuks

Copy link
Copy Markdown
Contributor

Closes #1376

Summary

Adds privacy-first, opt-in analytics consent UI, settings toggle, batched beacon transport, and route/deposit-funnel instrumentation.

What Changed

  • Consent & Preferences (src/utils/userPrefs.ts, src/components/ConsentBanner.tsx)
    • Extended UserPrefs with analyticsConsentDecided (default false) so declining does not re-prompt, with safe fallback for malformed stored preferences.
    • Added a non-blocking, keyboard-accessible ConsentBanner (role="region") with Accept/Decline actions.
    • Added an AnalyticsToggle (role="switch") in the app header that reads/writes analyticsConsent via setPref and stays synced with the banner.
  • Batched Transport (src/services/AnalyticsService.ts)
    • Replaced console-only logging with an in-memory queue that flushes at 10 events or every 5 seconds.
    • Sends batches to apiUrl('/api/analytics/events') via navigator.sendBeacon with a fetch(..., { method: 'POST', keepalive: true }) fallback.
    • Flushes remaining events on pagehide and visibilitychange (hidden), caps retries at 3, never enqueues while consent is false, and immediately clears the queue when consent is revoked.
  • Instrumentation (src/App.tsx)
    • Tracks deduplicated route_view events on pathname change ({ path } only — no query strings or user IDs).
    • Tracks deposit funnel events (deposit_started, deposit_signed, deposit_confirmed, deposit_failed) with only { network } (and error code reason on failure) — no wallet addresses, amounts, tokens, or transaction hashes.
  • Documentation (docs/Configuration.md)
    • Added an Analytics and privacy section documenting the privacy stance, batching/transport details, and event catalog.
  • Tests (src/services/AnalyticsService.test.ts, src/components/ConsentBanner.test.tsx)
    • Added unit tests for batch/timer flushing (fake timers), pagehide/visibilitychange flush, sendBeacon absent fallback, retry cap, revoke-clears-queue, secret redaction, consent banner persistence, toggle sync, and malformed stored prefs.

Testing

  • npx vitest run src/services/AnalyticsService.test.ts src/utils/userPrefs.test.ts src/components/ConsentBanner.test.tsx src/App.deposit.test.tsx
  • npm run typecheck (0 errors in touched files)

@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

@Opulencechuks Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

pr-malware-guard: resolved

No rules match the latest changes any more. Thank you!

@github-actions github-actions Bot added the needs-security-review Needs a maintainer security review (pr-malware-guard) label Nov 24, 2026
@github-actions github-actions Bot removed the needs-security-review Needs a maintainer security review (pr-malware-guard) label Nov 25, 2026
@greatest0fallt1me
greatest0fallt1me merged commit cd14317 into CalloraOrg:main Nov 26, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Thanks @Opulencechuks! Merged. 🎉

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.

Ship consent-gated analytics end to end

2 participants