@@ -48,9 +48,7 @@ func getClient() (posthog.Client, error) {
4848 return client , clientErr
4949}
5050
51- // IsAnalyticsFeatureEnabled checks the PostHog feature flag that acts as a
52- // remote kill switch for CLI telemetry. Lets us globally disable capture
53- // without shipping a CLI release.
51+ // IsAnalyticsFeatureEnabled is the remote kill switch for CLI telemetry; gating capture lets us turn it off without a release.
5452func IsAnalyticsFeatureEnabled () bool {
5553 anonID := GetOrCreateAnalyticsID ()
5654 if anonID == "" {
@@ -82,11 +80,9 @@ func RecordCommandStart(cmd *cobra.Command, args []string) {
8280 storedArgs = args
8381}
8482
85- // IsAnalyticsEnabled returns whether analytics capture is currently enabled.
86- // Default is on (opt-out model). Honors DO_NOT_TRACK and BREV_NO_ANALYTICS env
87- // vars as a kill switch for CI / scripted use.
83+ // IsAnalyticsEnabled defaults to true; DO_NOT_TRACK and BREV_NO_ANALYTICS override.
8884func IsAnalyticsEnabled () bool {
89- if os . Getenv ( "DO_NOT_TRACK" ) == "1" || os . Getenv ( "BREV_NO_ANALYTICS" ) == "1" {
85+ if disabled , _ := IsDisabledByEnv (); disabled {
9086 return false
9187 }
9288 settings := readSettings ()
@@ -96,8 +92,6 @@ func IsAnalyticsEnabled() bool {
9692 return * settings .AnalyticsEnabled
9793}
9894
99- // IsDisabledByEnv reports whether analytics is currently disabled by an
100- // environment-variable kill switch (vs. the user's persisted preference).
10195func IsDisabledByEnv () (disabled bool , varName string ) {
10296 if os .Getenv ("DO_NOT_TRACK" ) == "1" {
10397 return true , "DO_NOT_TRACK"
@@ -108,13 +102,6 @@ func IsDisabledByEnv() (disabled bool, varName string) {
108102 return false , ""
109103}
110104
111- // IsAnalyticsExplicitlySet reports whether the user has explicitly chosen a
112- // preference (true/false), as opposed to leaving it at the default.
113- func IsAnalyticsExplicitlySet () bool {
114- settings := readSettings ()
115- return settings .AnalyticsEnabled != nil
116- }
117-
118105// SetAnalyticsPreference persists the user's analytics preference.
119106func SetAnalyticsPreference (enabled bool ) error {
120107 fs := files .AppFs
@@ -202,14 +189,7 @@ func CaptureCommandError() {
202189 if storedCmd == nil {
203190 return
204191 }
205- // If CaptureCommand already ran (success path), don't double-capture.
206- // storedUser being set means PersistentPostRunE ran.
207- // We only get here on error, so PersistentPostRunE didn't run.
208- userID := storedUser
209- if userID == "" {
210- userID = GetOrCreateAnalyticsID ()
211- }
212- captureEvent (userID , storedCmd , storedArgs , false )
192+ captureEvent (storedUser , storedCmd , storedArgs , false )
213193}
214194
215195func captureEvent (userID string , cmd * cobra.Command , args []string , succeeded bool ) {
@@ -220,6 +200,11 @@ func captureEvent(userID string, cmd *cobra.Command, args []string, succeeded bo
220200 return
221201 }
222202
203+ // Resolve the analytics ID lazily, only after gates pass — avoids writing a
204+ // persistent UUID to ~/.brev/personal_settings.json for opted-out users.
205+ if userID == "" {
206+ userID = GetOrCreateAnalyticsID ()
207+ }
223208 if userID == "" {
224209 return
225210 }
0 commit comments