fix(analytics): respect data collection setting for all tracking events (#14390)

## 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) <noreply@anthropic.com>
Co-authored-by: suyao <sy20010504@gmail.com>
This commit is contained in:
于小丘
2026-04-20 11:26:54 +08:00
committed by GitHub
parent da2302237b
commit 7c2ada6d6a

View File

@@ -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<void> {
if (!this.client) {
if (!this.client || !configManager.getEnableDataCollection()) {
return
}