Commit 5305019
feat(web): rename PostHog chat events, add tool_used tracking, and client-side ask events (#1111)
* feat(web): rename PostHog chat events, add tool_used tracking, and add client-side ask events
Renames server-side chat events to drop the wa_ prefix (since they fire from
multiple sources), adds a new tool_used event for unified tool call tracking
across the ask agent and MCP server, and introduces client-side wa_ask_* events
for accurate web-only usage dashboards.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: add CHANGELOG entry for PostHog event changes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(web): add missing properties to client-side ask events
Add isAnonymous to wa_ask_thread_created and messageCount to
wa_ask_message_sent so they carry the same data as the server-side
events.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(web): remove redundant api_code_search_request event
This event is fully covered by api_request which fires for every API
call and carries path + source. Updated the Any Feature Usage PostHog
action to remove the api_code_search_request step.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(web): remove redundant wa_ask_thread_created event
Redundant with ask_thread_created which fires server-side for the same
thread creation (including from the web UI via createChat server action).
Dashboards track ask usage via wa_ask_message_sent, not thread creation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(web): remove wa_ask_message_sent, set source header on chat transport
Instead of a separate client-side event, the web client now sets the
X-Sourcebot-Client-Source header on DefaultChatTransport. This makes
ask_message_sent fire with source='sourcebot-web-client' for web UI
calls, enabling web-only filtering directly on the server-side event.
Updated Ask Usage and Any Feature Usage PostHog actions to filter
ask_message_sent by source=sourcebot-web-client.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: consolidate CHANGELOG entries for #1111 into single entry
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(web): handle unhandled promise rejections in tool_used captureEvent calls
Add .catch(() => {}) to all fire-and-forget captureEvent('tool_used')
calls in adapters.ts and server.ts, matching the existing pattern in
apiHandler.ts. Prevents unhandled promise rejections if telemetry fails.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(web): fix inflated MCP DAU by threading user identity through tool telemetry
captureEvent() relies on tryGetPostHogDistinctId() which reads cookies,
session, or API key headers. In the MCP server and ask agent contexts,
none of these are available, so every tool_used event got a random
distinct_id — inflating DAU counts (e.g., 8 tool calls = 8 "users").
Fix: add optional distinctId to ToolContext and captureEvent(). Thread
user.id from the auth context through:
- MCP route → createMcpServer(userId) → ToolContext.distinctId
- chat route / askCodebase → createMessageStream(distinctId) →
createAgentStream → createTools
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(web): rename distinctId to userId in ToolContext
The field carries a user ID, not a PostHog-specific concept. The
captureEvent options parameter remains distinctId since that's the
PostHog term, but the application-level interfaces use userId.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(web): use try/finally pattern in registerMcpTool for tool_used event
Match the same pattern used in toVercelAITool — single captureEvent call
in a finally block with a success boolean, instead of duplicated calls
in try and catch.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(web): move captureEvent error handling into captureEvent itself
captureEvent now wraps its body in try/catch so callers are guaranteed
it won't throw. Removed all .catch() handlers from call sites in
adapters.ts, server.ts, and apiHandler.ts.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor(web): fix tryGetPostHogDistinctId to use getAuthenticatedUser
tryGetPostHogDistinctId() was missing OAuth Bearer token resolution,
causing all MCP tool calls to get random distinct_ids (inflated DAU).
Fix: replace the manual cookie/session/API key checks with a call to
getAuthenticatedUser(), which already handles all auth methods (session,
OAuth, API keys). This removes the need to thread userId through
ToolContext, agent options, and all callers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(web): add error logging in captureEvent catch block
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent ae4513e commit 5305019
File tree
14 files changed
+104
-77
lines changed- packages/web/src
- app/api/(server)
- chat
- search
- stream_search
- features
- chat
- components/chatThread
- mcp
- tools
- lib
14 files changed
+104
-77
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| 100 | + | |
98 | 101 | | |
99 | | - | |
| 102 | + | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 23 | | |
31 | 24 | | |
32 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 22 | | |
30 | 23 | | |
31 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
210 | 209 | | |
211 | 210 | | |
212 | 211 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 212 | + | |
220 | 213 | | |
221 | 214 | | |
222 | 215 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
140 | | - | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| 145 | + | |
144 | 146 | | |
145 | 147 | | |
146 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| |||
101 | 107 | | |
102 | 108 | | |
103 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
104 | 115 | | |
105 | 116 | | |
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
109 | 126 | | |
110 | 127 | | |
111 | 128 | | |
| |||
0 commit comments