Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/analytics/posthog.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ func GetOrCreateAnalyticsID() string {
return settings.AnalyticsID
}

// CaptureAnalyticsOptIn sends an event recording the user's analytics consent choice.
// This is sent regardless of the user's choice so we can measure opt-in rates.
func CaptureAnalyticsOptIn(optedIn bool) {
anonID := GetOrCreateAnalyticsID()
if anonID == "" {
return
}

c, err := getClient()
if err != nil {
return
}

_ = c.Enqueue(posthog.Capture{
DistinctId: anonID,
Event: "analytics_opt_in",
Properties: posthog.NewProperties().
Set("opted_in", optedIn).
Set("os", runtime.GOOS).
Set("arch", runtime.GOARCH).
Set("cli_version", version.Version),
})
}

// IdentifyUser links the anonymous analytics ID to a real user ID using PostHog Alias.
func IdentifyUser(userID string) {
enabled, asked := IsAnalyticsEnabled()
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (o LoginOptions) handleOnboarding(user *entity.User, _ *terminal.Terminal)
})
optIn := strings.HasPrefix(choice, "Yes")
_ = analytics.SetAnalyticsPreference(optIn)
analytics.CaptureAnalyticsOptIn(optIn)
}

analytics.IdentifyUser(user.ID)
Expand Down
Loading