fix(#701): disable telemetry by default for self-hosted (OIDC) instances
This PR updates the default settings for data collection to be opt-in rather than opt-out for self-hosted/enterprise environments.
Changes:
- Centralized Logic: Introduced
getDefaultDataCollectionValueinsrc/defaults/settings.tsto manage the default-value logic. - Improved Implementation: Refactored to use the existing
isOidcMode()utility from@/lib/auth-mode, ensuring consistency and preventing logic drift. - Cleaned up Call Sites: Removed manual
import.meta.envpassing when calling the helper insettings.ts,posthog.tsx, andpreferences.tsx. - Tests: Added and updated unit tests in
src/defaults/settings.test.tsto verify the logic across different modes using mocked module behavior.
Validation:
- Verified that
data_collectiondefaults tofalsewhenisOidcMode()is true. - Verified that
data_collectiondefaults totruefor consumer mode. - All tests passed via
bun test.
Closes #701
[!NOTE] Low Risk Low risk: only flips the default
data_collectionsetting to opt-out, primarily affecting analytics initialization and the preferences UI default state.Overview Telemetry is now disabled by default by changing the default
data_collectionsetting value tofalse.This default is applied consistently in both PostHog initialization (
initPosthogfallback settings) and the Preferences settings page (useSettingsdefaults), so new/unspecified installs start with analytics opt-out unless the user enables it.Reviewed by Cursor Bugbot for commit 40bfcc266a2e4b8579a819f02bdeb0f2e0e11ebf. Bugbot is set up for automated code reviews on this repo. Configure here.
Hey @rbalogic thanks so much for this PR! Really appreciate the contribution.
I'd love to see this get merged if you want to make a few adjustments:
- We can actually go ahead and disable telemetry by default fully (eg just make it false instead of dependent on OIDC mode). The reasoning here is that OIDC is one auth method, but isn't necessarily what I would use as the determining factor for whether a deployment is self-hosted or not.
- Since we're defaulting to not enabled, we can simply use the presence of a posthog api key in the backend env vars as the determining factor. If there's no env key provided, we simply don't pass anything to the frontend, and the frontend simply shouldn't enable it.
- The other thing is that I'd say we can probably remove the tests - or if any tests do make sense, we can find a way to use dependency injection instead of mocking.
@cjroth Thanks for the feedback! 🙌
I’ve implemented the requested changes:
- Telemetry is now disabled by default unconditionally (no longer tied to OIDC mode). The frontend default for
data_collectionis now simplyfalse. - Kept the frontend behavior aligned with the existing flow: if the backend does not provide a usable PostHog API key, PostHog won’t initialize on the client.
- Removed the mock-based tests that covered the OIDC-dependent defaulting logic, since that logic is no longer needed.
Please take another look when you have a moment—happy to iterate further or make any additional tweaks before merge. Thanks again for the guidance!
@cjroth Please review the changes when you can, Thanks.
Preview environment destroyed 🧹
Stack preview-pr-714 and its Cloudflare subdomain have been cleaned up.
Hi @cjroth @raivieiraadriano92 @darkbanjo @ital0 Can you please review this PR when you have some time? Thanks.
Thanks for the contribution @rbalogic!