From 7c2ada6d6a2612ee94b19e7621620e97baf5871d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E5=B0=8F=E4=B8=98?= Date: Mon, 20 Apr 2026 11:26:54 +0800 Subject: [PATCH] fix(analytics): respect data collection setting for all tracking events (#14390) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - `trackAppLaunch` (called unconditionally in `init()`) and `trackAppUpdate` currently **bypass** the `enableDataCollection` user setting, sending telemetry to `analytics.cherry-ai.com` even when users have explicitly disabled data collection. - Only `trackTokenUsage` correctly checks `configManager.getEnableDataCollection()`. - This regression was introduced in 6061d472 (2026-03-22), which removed the original opt-out guard from `init()` that existed since the initial implementation in 1734467f. ## Changes - Add `enableDataCollection` check before `trackAppLaunch` in `init()` - Add `enableDataCollection` check in `trackAppUpdate()` - All three tracking methods now consistently respect the user's data collection preference ## Test plan - [x] `pnpm lint` passes - [x] `pnpm test` passes (2 pre-existing symlink failures on Windows, unrelated) - [ ] Verify with data collection **enabled**: all three events (`app_launch`, `token_usage`, `app_update`) are sent normally - [ ] Verify with data collection **disabled**: no events are sent to `analytics.cherry-ai.com` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) Co-authored-by: suyao --- src/main/services/AnalyticsService.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/services/AnalyticsService.ts b/src/main/services/AnalyticsService.ts index e5b70f0b59..1b084003fa 100644 --- a/src/main/services/AnalyticsService.ts +++ b/src/main/services/AnalyticsService.ts @@ -21,6 +21,11 @@ class AnalyticsService { } public init(): void { + if (!configManager.getEnableDataCollection()) { + logger.info('Analytics service disabled by user preference') + return + } + this.client = new AnalyticsClient({ clientId: configManager.getClientId(), channel: 'cherry-studio', @@ -53,7 +58,7 @@ class AnalyticsService { } public async trackAppUpdate(): Promise { - if (!this.client) { + if (!this.client || !configManager.getEnableDataCollection()) { return }