Skip to content

Commit 0ff745e

Browse files
authored
feat(analytics): gate analytics prompt behind PostHog feature flag (#302)
Use the `enable-cli-analytics` PostHog feature flag to control whether users are prompted about analytics opt-in during login. Analytics is disabled by default unless the flag is enabled for the user.
1 parent e47fdbe commit 0ff745e

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

pkg/analytics/posthog.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ func getClient() (posthog.Client, error) {
4040
return client, clientErr
4141
}
4242

43+
// IsAnalyticsFeatureEnabled checks the PostHog feature flag to determine
44+
// whether to prompt the user about analytics opt-in.
45+
func IsAnalyticsFeatureEnabled() bool {
46+
anonID := GetOrCreateAnalyticsID()
47+
if anonID == "" {
48+
return false
49+
}
50+
51+
c, err := getClient()
52+
if err != nil {
53+
return false
54+
}
55+
56+
result, err := c.IsFeatureEnabled(posthog.FeatureFlagPayload{
57+
Key: "enable-cli-analytics",
58+
DistinctId: anonID,
59+
})
60+
if err != nil {
61+
return false
62+
}
63+
64+
enabled, ok := result.(bool)
65+
return ok && enabled
66+
}
67+
4368
// RecordCommandStart should be called from PersistentPreRunE to record the start time
4469
// and store the command context for potential error-path capture.
4570
func RecordCommandStart(cmd *cobra.Command, args []string) {

pkg/cmd/login/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (o LoginOptions) handleOnboarding(user *entity.User, _ *terminal.Terminal)
233233
}
234234

235235
_, analyticsAsked := analytics.IsAnalyticsEnabled()
236-
if !analyticsAsked {
236+
if !analyticsAsked && analytics.IsAnalyticsFeatureEnabled() {
237237
choice := terminal.PromptSelectInput(terminal.PromptSelectContent{
238238
Label: "Help us improve Brev by sharing usage data?",
239239
ErrorMsg: "Error: must choose an option",

0 commit comments

Comments
 (0)