Files
fission-ai__openspec/openspec/changes/archive/2026-01-09-add-posthog-analytics/tasks.md
Tabish Bidiwale 940898c1c5 Add optional anonymous usage statistics (#468)
* chore: add proposal for PostHog analytics integration

Introduces the proposal artifact for adding opt-in telemetry to OpenSpec
using PostHog. Covers command tracking, feature adoption metrics, and
privacy-respecting consent management.

* feat: add optional anonymous usage statistics

Introduces privacy-first usage analytics to help understand how OpenSpec
is being used. Key privacy protections:

- Only tracks command names and version (no arguments, paths, or content)
- Opt-out via OPENSPEC_TELEMETRY=0 or DO_NOT_TRACK=1
- Auto-disabled in CI environments
- No IP address collection (explicitly disabled)
- Anonymous ID is a random UUID with no PII

Uses PostHog with a reverse proxy to avoid ad blockers. First-run shows
a one-line notice informing users about the collection.

* docs: make telemetry section collapsible and concise
2026-01-09 23:10:31 -08:00

1.9 KiB

1. Setup

  • 1.1 Add posthog-node package as a dependency
  • 1.2 Create src/telemetry/ module directory
  • 1.3 Add PostHog API key configuration (environment variable or embedded)

2. Global Config

  • 2.1 Create or extend global config module for ~/.config/openspec/config.json
  • 2.2 Implement read/write functions that preserve existing config fields
  • 2.3 Define telemetry config structure (anonymousId, noticeSeen)

3. Core Telemetry Module

  • 3.1 Implement isTelemetryEnabled() checking OPENSPEC_TELEMETRY, DO_NOT_TRACK, and CI env vars
  • 3.2 Implement getOrCreateAnonymousId() with lazy UUID generation
  • 3.3 Initialize PostHog client with flushAt: 1 and flushInterval: 0
  • 3.4 Implement trackCommand(commandName, version) with $ip: null
  • 3.5 Implement shutdown() with try/catch for silent failure handling

4. First-Run Notice

  • 4.1 Implement maybeShowTelemetryNotice() function
  • 4.2 Check noticeSeen flag before displaying notice
  • 4.3 Display notice text: "Note: OpenSpec collects anonymous usage stats. Opt out: OPENSPEC_TELEMETRY=0"
  • 4.4 Update noticeSeen in config after first display

5. CLI Integration

  • 5.1 Add Commander.js preAction hook to show notice and track command
  • 5.2 Add Commander.js postAction hook to call shutdown
  • 5.3 Handle subcommand path extraction (e.g., change:apply)

6. Testing

  • 6.1 Test opt-out via OPENSPEC_TELEMETRY=0
  • 6.2 Test opt-out via DO_NOT_TRACK=1
  • 6.3 Test auto-disable in CI environment
  • 6.4 Test first-run notice display and noticeSeen persistence
  • 6.5 Test anonymous ID generation and persistence
  • 6.6 Test silent failure on network error (mock PostHog)

7. Documentation

  • 7.1 Add telemetry disclosure section to README
  • 7.2 Document opt-out methods (OPENSPEC_TELEMETRY=0, DO_NOT_TRACK=1)
  • 7.3 Document what data is collected and not collected