Skip to content

Comments

feat(analytics): add PostHog analytics for CLI command tracking#293

Open
theFong wants to merge 8 commits intomainfrom
feat/posthog-analytics
Open

feat(analytics): add PostHog analytics for CLI command tracking#293
theFong wants to merge 8 commits intomainfrom
feat/posthog-analytics

Conversation

@theFong
Copy link
Member

@theFong theFong commented Feb 25, 2026

Summary

  • Adds PostHog SDK integration for comprehensive, privacy-conscious CLI analytics
  • Captures every command invocation generically via PersistentPostRunE on the root command
  • Users are prompted to opt in during brev login, with preference persisted in ~/.brev/personal_settings.json
  • Anonymous users get a stable UUID; on login, posthog.Alias links anonymous and real user IDs

Tracked Properties

Property Source
command, args, flags Cobra command context
succeeded, duration_ms Execution result + timer
cli_version, go_version Build/runtime info
os, arch, num_cpus runtime package
cwd os.Getwd()
is_tty, is_stdin_piped File descriptor stat
shell, terminal $SHELL, $TERM
is_ci Checks CI, GITHUB_ACTIONS, GITLAB_CI, etc.
is_ssh $SSH_TTY, $SSH_CONNECTION
locale, timezone $LANG / time.Now().Zone()
gpu_info nvidia-smi or system_profiler on macOS
parent_process, parent_cmdline Parent PID inspection

Test plan

  • go build compiles successfully
  • Run brev login — should prompt for analytics preference after auth
  • Check ~/.brev/personal_settings.json has analytics_enabled and analytics_id
  • Run brev ls — if opted in, cli_command event should appear in PostHog
  • Run brev login again — should NOT re-prompt (preference already set)
  • Run invalid command — error event should fire with succeeded: false
  • Existing tests pass

Add comprehensive, privacy-conscious analytics using PostHog that
captures every command invocation with args, flags, execution context,
and system info. Users are prompted to opt in during login, with
preference stored in personal_settings.json.

Tracked properties include: command path, duration, success/failure,
OS/arch, CLI version, TTY/pipe detection, CI/SSH detection, shell,
locale, timezone, GPU info, parent process, and cwd.
@theFong theFong requested a review from a team as a code owner February 25, 2026 06:29
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