Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(cli): send telemetry direct to PostHog; stitch install→Apollo identity (#3927)
## What Sends CLI telemetry **directly to PostHog** (project 196278) instead of through Apollo/Segment, and stitches the anonymous install identity to the Apollo user at login. This unlocks the previously-dark top of the CLI adoption funnel (install → setup → login → connect → execute). ### Why Two live funnel breaks in PostHog today: 1. **Install/setup/plugin events were dark.** Pre-login, `dispatch.ts` had no API base URL (→ endpoint null → dropped), and Apollo's ingest 401s anonymous requests. So `CLI_INSTALL_*`/`CLI_SETUP_*` never arrived. 2. **Identity split.** CLI/server events landed on *email*-keyed PostHog persons (via Segment); dashboard onboarding on *UUID*-keyed persons — the two never joined. The CLI already knows the canonical Apollo UUID (`org_member.id` from session info), so it can self-stitch with no platform/dashboard change. ## How - **Direct transport.** New PostHog capture path (`captureToPostHog`) reusing the existing detached best-effort worker. No dependency on the API base URL, so **pre-login events send**. - **Identity.** Pre-login `distinct_id = install_id`; at login `linkApolloIdentityForAnalytics(org_member.id)` persists the UUID to `~/.composio/analytics.json` and fires one `$create_alias` (`install_id → org_member.id`); post-login events key on the persisted `apollo_user_id`. Because onboarding is already UUID-keyed, the CLI funnel now joins web onboarding. - **Public key, baked at build.** The write-only `phc_` project key is injected via `bun build --define` from the `COMPOSIO_POSTHOG_KEY` env (CI Actions **variable**), never committed to source. `--define` (not a second `--env`) is deliberate — Bun honors only the last `--env`, which would clobber the existing `DEBUG_OVERRIDE_*` bake. For this OSS repo this keeps the key out of git history and means **forks / local builds compile a no-op binary** (only official releases carry the key). - **Direct-only:** the Apollo `/cli/analytics` send is dropped for CLI events; the CLI attaches its own `org_id` (project_id is per-session; a follow-up). ## Guards No-op (no send, no worker spawn, no identity-file write) when telemetry is disabled (`COMPOSIO_CLI_TELEMETRY_DISABLED`/`TELEMETRY_DISABLED`/`COMPOSIO_DISABLE_TELEMETRY`/`CI`/`NODE_ENV=test`) or when no project key is configured. Alias fires once per install (idempotent). No user API key or tool-arg values in event properties. ## Verification - `pnpm typecheck`, `validate:boundaries`, full CLI vitest (**954 passed / 1 skipped**) — green. - Independent code review pass; findings addressed (spawn-gated-on-key, disabled=no-file, idempotent alias). - **Live cold-install trace:** built the real compiled binary with the key baked, ran it from a throwaway `$HOME` → fresh `install_id` → 2 pre-login events delivered to `us.i.posthog.com` with **HTTP 200** → confirmed queryable in PostHog 196278 within ~10s, keyed by `install_id`. ## Notes - CLI is Changesets-ignored; human note added to `CHANGELOG.md` directly. - Requires the `COMPOSIO_POSTHOG_KEY` Actions variable to be set for official release builds (done). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
No changes.