Open History to see the last commit
1# Product analytics
2
3The server owns analytics delivery, opt-out, and identity for every connected client.
4Clients do not load the PostHog browser SDK. Client-use events require an
5authenticated connection, so visiting the hosted app without connecting does not
6count as product use.
7
8## Installs and owners
9
10`distinct_id` keeps the rule every build has used: the hashed Codex workspace,
11else the Claude machine id, else the install's anonymous id. It can change when
12someone logs in, and a Codex Team shares one, but keeping it means PostHog charts
13and history never break. Do not change it; add a field instead.
14
15Every event also carries `installId` when the server can save its state: the hash
16of a random id in the state directory, which never changes for the install. If
17that file cannot be written, events still go out under `distinct_id`, as before. Count installs
18with it. Who an install belongs to is a separate fact, sent as
19`install.owner_observed`. Owners are resolved at query time in our own store, so
20a rule can change and apply to all history.
21
22[Owner sources](../../apps/server/src/telemetry/Identify.ts), strongest first:
23T3 Connect, then the OpenAI and Claude person ids, then the client device. The
24server reports what it can read itself: the linked Connect account and provider
25logins. A connecting client reports its signed-in Connect account and its device,
26which links every environment opened from one phone, browser, or desktop. Use the
27OpenAI `user_id` claim, not the Codex `account_id` (the ChatGPT workspace, which a
28whole Team shares) or the token `sub` (one per login method). Two Connect accounts are never the same person, whatever
29weaker ids they share.
30
31Every id is SHA-256 hashed with [one helper](../../packages/shared/src/telemetryId.ts)
32on both sides, so a Connect account hashes the same on the client and the server.
33The server accepts only hashes from clients.
34
35## Attribution boundaries
36
37Client dimensions belong to the event's WebSocket connection. A server-global
38"current client" would misattribute simultaneous web, desktop, and mobile use.
39Provider execution has its own events because a turn can outlive the requesting
40connection.
41
42Keep client and server dimensions separate. A desktop host can serve a phone or a
43remote browser, and a direct connection can cross a network. Older clients omit
44metadata. Missing client values must stay unknown rather than being backfilled
45from server properties. The legacy `clientType` property describes how the server
46runs; use `surface` for the connected client.
47
48## Interpreting events
49
50Use `client.turn.requested` for active-use reports. `client.connected` counts
51reconnects, so network behavior can inflate it. One identity can appear in several
52client groups during a period; adding those groups double-counts users.
53
54Provider send and completion counts need not match. Providers can emit synthetic
55turns without a send request. Collection is best effort, with no scan or backfill
56of provider history.
57
58Token totals cover the main agent. Child agents and model rerouting prevent a turn
59from representing one provider/model combination's full cost. For provider
60comparisons, require complete usage, no observed subagents, and no mixed models;
61compare matching model, effort, interaction mode, and terminal status. Aggregate
62output/input ratios should divide the summed totals. Averaging per-turn ratios
63lets small-input turns dominate.
64
65Unknown counts stay absent. Partial usage contains valid observed counts but
66cannot establish a whole-turn total. Keep these distinctions when changing token
67normalization or building reports.
68
69`feature.used` counts WebSocket requests that start a feature, observed in the
70RPC authorization middleware after the request succeeds.
71[Feature mapping](../../apps/server/src/telemetry/FeatureUsage.ts) allowlists
72the methods and commands, and takes variants only from closed contract enums,
73so paths, ids, and text never reach analytics.
74
75Agent tool events report driver kinds, never instance ids: users name
76instances, so an instance id can identify an account or employer.
77[Provider dimensions](../../apps/server/src/telemetry/ProviderDimensions.ts)
78report a model only when it is a non-custom entry in a vendor catalog. OpenCode,
79Pi, and ACP agents list models from user configuration, such as local Ollama
80tags, so their models stay out. Handoff settings come from closed enums and
81booleans in tool arguments; prompts, titles, and ids are never read. Thread ids
82are used only to look up the threads on each side and never leave the server,
83which is also why tool events carry no per-thread sequence.
84
85## Delivery
86
87The server sends batches to the ingest endpoint at `ingest.t3.codes`, which archives
88every event and forwards some of them to PostHog. A send can fail after the endpoint
89has stored the batch, so every retry is a copy.
90[Delivery](../../apps/server/src/telemetry/AnalyticsService.ts) gives each event a
91uuid when it is recorded (the endpoint rejects events without one), backs off after
92a failed send, and drops a batch after a few tries. Without these limits, one stuck
93batch was sent every second for days.
94
95## Collection boundary
96
97Keep analytics payloads to product metadata and normalized measurements. Do not
98send prompts, authentication material, raw provider payloads, user-assigned device
99names, or conversation identifiers. Client metadata is best effort; invalid values
100must not reject a connection. PostHog person profiles remain disabled.