Skip to content

feat(desktop): add setting to disable telemetry - #1130

Closed
AviPeltz wants to merge 1 commit into
mainfrom
avipeltz/disable-telemetry
Closed

AviPeltz wants to merge 1 commit into
mainfrom
avipeltz/disable-telemetry

Conversation

@AviPeltz

@AviPeltz AviPeltz commented Feb 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a toggle in Settings > Features to disable anonymous usage data (PostHog analytics)
  • Telemetry is enabled by default
  • Sentry error tracking remains enabled regardless of this setting

Test plan

  • Toggle the "Send anonymous usage data" switch off in Settings > Features
  • Verify PostHog events stop being sent (check network tab or PostHog dashboard)
  • Toggle it back on and verify events resume
  • Restart the app and verify the setting persists
  • Search for "telemetry" in settings and verify the setting appears

Summary by CodeRabbit

  • New Features
    • Users can now control telemetry settings in Settings > Behavior to enable or disable the sending of anonymous usage data.

@coderabbitai

coderabbitai Bot commented Feb 2, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Introduces telemetry opt-in/opt-out functionality by adding database schema support, TRPC endpoints, analytics gating logic, a React synchronization component, and settings UI controls to allow users to manage telemetry collection preferences.

Changes

Cohort / File(s) Summary
Database Schema
packages/local-db/drizzle/0016_add_telemetry_enabled.sql, packages/local-db/drizzle/meta/..., packages/local-db/src/schema/schema.ts
Adds telemetry_enabled integer column to settings table with schema snapshot and migration metadata.
Settings Backend
apps/desktop/src/lib/trpc/routers/settings/index.ts
Introduces getTelemetryEnabled query and setTelemetryEnabled mutation endpoints with DEFAULT_TELEMETRY_ENABLED fallback and upsert logic.
Analytics Integration
apps/desktop/src/main/lib/analytics/index.ts
Adds telemetry enablement check that gates tracking calls; reads from local DB with error fallback.
Telemetry Sync Component
apps/desktop/src/renderer/components/TelemetrySync/...
New React component subscribes to telemetryEnabled via TRPC and syncs PostHog opt_in/opt_out state; includes index export.
Settings UI & Search
apps/desktop/src/renderer/routes/_authenticated/settings/behavior/components/BehaviorSettings/BehaviorSettings.tsx, apps/desktop/src/renderer/routes/_authenticated/settings/utils/settings-search/settings-search.ts
Adds telemetry toggle UI with loading/mutation states and conditional visibility; registers BEHAVIOR_TELEMETRY setting item with keywords.
Constants & Routing
apps/desktop/src/shared/constants.ts, apps/desktop/src/renderer/routes/layout.tsx
Introduces DEFAULT_TELEMETRY_ENABLED constant; integrates TelemetrySync component into root layout.

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as BehaviorSettings UI
    participant TRPC as Settings TRPC
    participant DB as Local DB
    participant Sync as TelemetrySync
    participant PostHog
    participant Analytics

    User->>UI: Toggle telemetry switch
    UI->>TRPC: setTelemetryEnabled(enabled)
    TRPC->>DB: Update settings.telemetry_enabled
    DB-->>TRPC: Confirmed
    TRPC-->>UI: Mutation resolves
    
    Sync->>TRPC: Subscribe to getTelemetryEnabled
    TRPC->>DB: Read telemetry_enabled
    DB-->>TRPC: Return value
    TRPC-->>Sync: telemetryEnabled state
    
    Sync->>PostHog: Call opt_in/opt_out_capturing()
    PostHog-->>Sync: Confirmed
    
    Analytics->>DB: Check isTelemetryEnabled
    DB-->>Analytics: Return telemetry_enabled
    alt Telemetry Enabled
        Analytics->>Analytics: Proceed with tracking
    else Telemetry Disabled
        Analytics->>Analytics: Skip tracking
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • Kitenite

Poem

🐰 Hop, hop, hooray! A telemetry toggle tale,
Users can now opt out without fail,
PostHog and DB in sync do play,
Privacy choices come out to stay! 📊✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately and concisely describes the main change: adding a setting to disable telemetry, which aligns with the primary objective of the changeset.
Description check ✅ Passed The PR description provides a clear summary of changes, includes a comprehensive test plan with checkboxes, but does not follow the provided template structure (missing Related Issues, Type of Change, Screenshots sections).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch avipeltz/disable-telemetry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/desktop/src/main/lib/analytics/index.ts`:
- Around line 26-32: The isTelemetryEnabled function currently swallows DB
errors; update its catch block to log the error with context before returning
the default value — e.g., use console.error with a prefixed message like
"[analytics/read-telemetry] Failed to read telemetry setting:" and include the
caught error object; keep the rest of the logic
(localDb.select().from(settings).get(), DEFAULT_TELEMETRY_ENABLED) unchanged so
it still returns the default on failure.
🧹 Nitpick comments (1)
apps/desktop/src/main/lib/analytics/index.ts (1)

39-45: Prefer a params object for track to avoid positional arguments.
This aligns with the 2+ params guideline and improves call-site clarity; update call sites accordingly.

Proposed refactor
-export function track(
-	event: string,
-	properties?: Record<string, unknown>,
-): void {
+export function track({
+	event,
+	properties,
+}: {
+	event: string;
+	properties?: Record<string, unknown>;
+}): void {

As per coding guidelines: Functions with 2+ parameters should accept a single params object with named properties instead of positional arguments.

Comment on lines +26 to +32
function isTelemetryEnabled(): boolean {
try {
const row = localDb.select().from(settings).get();
return row?.telemetryEnabled ?? DEFAULT_TELEMETRY_ENABLED;
} catch {
return DEFAULT_TELEMETRY_ENABLED;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Log telemetry read failures instead of silently falling back.
The empty catch hides DB errors and makes telemetry state issues hard to diagnose.

Proposed fix
-	} catch {
-		return DEFAULT_TELEMETRY_ENABLED;
-	}
+	} catch (error) {
+		console.error(
+			"[analytics/isTelemetryEnabled] Failed to read telemetry setting:",
+			error,
+		);
+		return DEFAULT_TELEMETRY_ENABLED;
+	}

As per coding guidelines: Never swallow errors silently; at minimum log them with context. Use prefixed console logging with pattern [domain/operation] message for all logging.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isTelemetryEnabled(): boolean {
try {
const row = localDb.select().from(settings).get();
return row?.telemetryEnabled ?? DEFAULT_TELEMETRY_ENABLED;
} catch {
return DEFAULT_TELEMETRY_ENABLED;
}
function isTelemetryEnabled(): boolean {
try {
const row = localDb.select().from(settings).get();
return row?.telemetryEnabled ?? DEFAULT_TELEMETRY_ENABLED;
} catch (error) {
console.error(
"[analytics/isTelemetryEnabled] Failed to read telemetry setting:",
error,
);
return DEFAULT_TELEMETRY_ENABLED;
}
}
🤖 Prompt for AI Agents
In `@apps/desktop/src/main/lib/analytics/index.ts` around lines 26 - 32, The
isTelemetryEnabled function currently swallows DB errors; update its catch block
to log the error with context before returning the default value — e.g., use
console.error with a prefixed message like "[analytics/read-telemetry] Failed to
read telemetry setting:" and include the caught error object; keep the rest of
the logic (localDb.select().from(settings).get(), DEFAULT_TELEMETRY_ENABLED)
unchanged so it still returns the default on failure.

@github-actions

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) ✅ View Branch
Fly.io Electric (Fly.io) ✅ View App
Vercel API (Vercel) ✅ Open Preview
Vercel Web (Vercel) ✅ Open Preview
Vercel Marketing (Vercel) ✅ Open Preview
Vercel Admin (Vercel) ✅ Open Preview
Vercel Docs (Vercel) ✅ Open Preview

Preview updates automatically with new commits

@AviPeltz AviPeltz closed this Feb 3, 2026
@Kitenite
Kitenite deleted the avipeltz/disable-telemetry branch February 4, 2026 20:42

This branch was previously deployed

1 inactive deployment
preview — 24ad27be Deployed Feb 2, 2026 by AviPeltz via Deploy Admin #1389
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant