Files
AFFiNE/packages/frontend/core/src/bootstrap/telemetry.ts
forehalo 25aa5701bd chore(core): fix mixpanel init (#12513)
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **Bug Fixes**
  - Adjusted telemetry settings to ensure Sentry is disabled when telemetry is enabled and clarified Mixpanel’s automatic opt-out behavior.

- **Documentation**
  - Added a comment explaining Mixpanel’s handling of telemetry preferences for improved transparency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-26 06:28:32 +00:00

23 lines
670 B
TypeScript

import { mixpanel, sentry } from '@affine/track';
import { APP_SETTINGS_STORAGE_KEY } from '@toeverything/infra/atom';
mixpanel.init();
sentry.init();
if (typeof localStorage !== 'undefined') {
let enabled = true;
const settingsStr = localStorage.getItem(APP_SETTINGS_STORAGE_KEY);
if (settingsStr) {
const parsed = JSON.parse(settingsStr);
enabled = parsed.enableTelemetry;
}
if (!enabled) {
// NOTE(@forehalo): mixpanel will read local storage flag and doesn't need to be manually opt_out at startup time.
// see: https://docs.mixpanel.com/docs/privacy/protecting-user-data
// mixpanel.opt_out_tracking();
sentry.disable();
}
}