fix(core): runtime control of telemetry (#10663)

This commit is contained in:
forehalo
2025-03-06 09:56:13 +00:00
parent 93920f9895
commit 56b842f2e1
5 changed files with 70 additions and 51 deletions

View File

@@ -1,4 +1,20 @@
import { mixpanel, sentry } from '@affine/track';
import { APP_SETTINGS_STORAGE_KEY } from '@toeverything/infra';
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) {
mixpanel.opt_out_tracking();
sentry.disable();
}
}

View File

@@ -1,11 +1,12 @@
import { enableAutoTrack, mixpanel, sentry } from '@affine/track';
import { appSettingAtom } from '@toeverything/infra';
import { useAtomValue } from 'jotai/react';
import { useLayoutEffect } from 'react';
import { useEffect } from 'react';
export function Telemetry() {
const settings = useAtomValue(appSettingAtom);
useLayoutEffect(() => {
useEffect(() => {
if (settings.enableTelemetry === false) {
sentry.disable();
mixpanel.opt_out_tracking();
@@ -16,5 +17,6 @@ export function Telemetry() {
return enableAutoTrack(document.body, mixpanel.track);
}
}, [settings.enableTelemetry]);
return null;
}