mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: defer PostHog/Sentry loading until user consents to telemetry
PostHog SDK was initialized on app mount based only on the server-level config flag, ignoring user consent. This caused network requests to us-assets.i.posthog.com (config.js, web-vitals.js, dead-clicks-autocapture.js) even when the user had not opted in or had explicitly declined telemetry. - Replace static imports of posthog-js and @sentry/react with dynamic import() so the SDK bundles are not downloaded until consent is granted - Gate initAnalytics on analyticsConsent.analyticsEnabled === true, not just server config.enabled - Add consent re-check after each await import() to handle revocation during the async load - Add shutdownAnalytics() that calls opt_out_capturing() + reset() for mid-session consent revocation - setAnalyticsConsent(false) now triggers full SDK shutdown automatically - Rewrite analytics test suite with 44 tests covering init gating, shutdown lifecycle, consent toggle, race conditions, and Sentry callbacks Closes #98
This commit is contained in:
@@ -108,6 +108,8 @@ export default defineConfig({
|
||||
react: path.join(webNodeModules, "react"),
|
||||
"react-dom": path.join(webNodeModules, "react-dom"),
|
||||
zustand: path.join(webNodeModules, "zustand"),
|
||||
"posthog-js": path.join(webNodeModules, "posthog-js"),
|
||||
"@sentry/react": path.join(webNodeModules, "@sentry/react"),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user