Skip to content

feat(code): anonymous PostHog usage analytics for CLI runs - #56

Merged
danii1 merged 1 commit into
mainfrom
feat/cli-analytics
Aug 24, 2026
Merged

feat(code): anonymous PostHog usage analytics for CLI runs#56
danii1 merged 1 commit into
mainfrom
feat/cli-analytics

Conversation

@danii1

@danii1 danii1 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Tracks anonymous usage of the devintern CLI via PostHog (same vendor as pm-desktop) to understand popularity and feature adoption. Branch is based cleanly on main.

  • One event per run (cli_run): CLI version, OS/arch, CI flag, tracker type, run mode (tasks/query/estimate), task count, and boolean feature flags (--create-pr, --auto-review, --estimate, sandbox provider). Sent fire-and-forget at run start; never blocks or fails the CLI.
  • Strict allowlist scrubbing (same pattern as pm-desktop analytics.ts): task content, code, repo names, paths, and credentials are never sent.
  • Anonymous ID: random UUID persisted per project in .devintern-code/telemetry.json; no accounts, emails, or IPs tied to profiles.
  • Opt-out: DEVINTERN_TELEMETRY_DISABLED=1 (shell or .devintern-code/.env) or analytics.enabled: false in .devintern-code/settings.json. A one-time console notice discloses collection on the first instrumented interactive run.
  • Build-time key injection: POSTHOG_API_KEY / POSTHOG_HOST baked into the bundle via build.ts defines; missing key permanently disables analytics, so source/dev builds and CI test runs are no-ops.
  • Docs: new "Anonymous Usage Analytics" section in docs/code/configuration.md.

Follow-ups

  • Update https://devintern.com/privacy/ (separate marketing-site repo) before shipping an instrumented release
  • Add POSTHOG_API_KEY secret to the npm publish pipeline so released builds instrument
  • Optionally add a PostHog dashboard for tracker-type / run-mode breakdowns

Test plan

  • New tests/analytics.test.ts (16 cases): env opt-out parsing, settings opt-out + malformed settings resilience, prop scrubbing, stable anonymous ID persistence, first-run detection, sender-failure safety
  • Full suite on this branch: 840 pass / 0 fail
  • bun run lint, bun run typecheck green
  • bun run build.ts succeeds; host string verified baked into dist/index.js

Send one fire-and-forget cli_run event per invocation: CLI version,
OS/arch, tracker type, run mode, task count, and feature flags only —
never task content, code, repo names, or credentials.

- New src/lib/analytics.ts: bare-fetch PostHog capture, per-project
  anonymous ID in .devintern-code/telemetry.json, allowlisted prop
  scrubbing, bounded flush on exit
- Opt out via DEVINTERN_TELEMETRY_DISABLED=1 (shell or .env) or
  analytics.enabled: false in .devintern-code/settings.json
- POSTHOG_API_KEY/POSTHOG_HOST baked at build time; missing key
  permanently disables analytics (source/dev builds are no-op)
- One-time disclosure notice on the first instrumented run
- Docs: new Anonymous Usage Analytics section in configuration.md
@danii1
danii1 merged commit 6c5b9d9 into main Aug 24, 2026
1 check passed
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