11import { useCallback } from "react" ;
2- import { trackEvent , roundToBase2 } from "@/common/telemetry" ;
3- import type { ErrorContext } from "@/common/telemetry/payload" ;
2+ import { trackEvent , roundToBase2 , getFrontendPlatformInfo } from "@/common/telemetry" ;
3+ import type {
4+ ErrorContext ,
5+ TelemetryRuntimeType ,
6+ TelemetryThinkingLevel ,
7+ TelemetryCommandType ,
8+ } from "@/common/telemetry/payload" ;
49
510/**
611 * Hook for clean telemetry integration in React components
@@ -16,11 +21,23 @@ import type { ErrorContext } from "@/common/telemetry/payload";
1621 * // Track workspace switch
1722 * telemetry.workspaceSwitched(fromId, toId);
1823 *
19- * // Track workspace creation
20- * telemetry.workspaceCreated(workspaceId);
24+ * // Track workspace creation (runtimeType: 'local' | 'worktree' | 'ssh')
25+ * telemetry.workspaceCreated(workspaceId, runtimeType );
2126 *
2227 * // Track message sent
23- * telemetry.messageSent(model, mode, messageLength);
28+ * telemetry.messageSent(model, mode, messageLength, runtimeType, thinkingLevel);
29+ *
30+ * // Track stream completion
31+ * telemetry.streamCompleted(model, wasInterrupted, durationSecs, outputTokens);
32+ *
33+ * // Track provider configuration
34+ * telemetry.providerConfigured(provider, keyType);
35+ *
36+ * // Track command usage
37+ * telemetry.commandUsed(commandType);
38+ *
39+ * // Track voice transcription
40+ * telemetry.voiceTranscription(audioDurationSecs, success);
2441 *
2542 * // Track error
2643 * telemetry.errorOccurred(errorType, context);
@@ -38,24 +55,104 @@ export function useTelemetry() {
3855 } ) ;
3956 } , [ ] ) ;
4057
41- const workspaceCreated = useCallback ( ( workspaceId : string ) => {
42- console . debug ( "[useTelemetry] workspaceCreated called" , { workspaceId } ) ;
58+ const workspaceCreated = useCallback ( ( workspaceId : string , runtimeType : TelemetryRuntimeType ) => {
59+ const frontendPlatform = getFrontendPlatformInfo ( ) ;
60+ console . debug ( "[useTelemetry] workspaceCreated called" , {
61+ workspaceId,
62+ runtimeType,
63+ frontendPlatform,
64+ } ) ;
4365 trackEvent ( {
4466 event : "workspace_created" ,
4567 properties : {
4668 workspaceId,
69+ runtimeType,
70+ frontendPlatform,
4771 } ,
4872 } ) ;
4973 } , [ ] ) ;
5074
51- const messageSent = useCallback ( ( model : string , mode : string , messageLength : number ) => {
52- console . debug ( "[useTelemetry] messageSent called" , { model, mode, messageLength } ) ;
53- trackEvent ( {
54- event : "message_sent" ,
55- properties : {
75+ const messageSent = useCallback (
76+ (
77+ model : string ,
78+ mode : string ,
79+ messageLength : number ,
80+ runtimeType : TelemetryRuntimeType ,
81+ thinkingLevel : TelemetryThinkingLevel
82+ ) => {
83+ const frontendPlatform = getFrontendPlatformInfo ( ) ;
84+ console . debug ( "[useTelemetry] messageSent called" , {
5685 model,
5786 mode,
58- message_length_b2 : roundToBase2 ( messageLength ) ,
87+ messageLength,
88+ runtimeType,
89+ thinkingLevel,
90+ frontendPlatform,
91+ } ) ;
92+ trackEvent ( {
93+ event : "message_sent" ,
94+ properties : {
95+ model,
96+ mode,
97+ message_length_b2 : roundToBase2 ( messageLength ) ,
98+ runtimeType,
99+ frontendPlatform,
100+ thinkingLevel,
101+ } ,
102+ } ) ;
103+ } ,
104+ [ ]
105+ ) ;
106+
107+ const streamCompleted = useCallback (
108+ ( model : string , wasInterrupted : boolean , durationSecs : number , outputTokens : number ) => {
109+ console . debug ( "[useTelemetry] streamCompleted called" , {
110+ model,
111+ wasInterrupted,
112+ durationSecs,
113+ outputTokens,
114+ } ) ;
115+ trackEvent ( {
116+ event : "stream_completed" ,
117+ properties : {
118+ model,
119+ wasInterrupted,
120+ duration_b2 : roundToBase2 ( durationSecs ) ,
121+ output_tokens_b2 : roundToBase2 ( outputTokens ) ,
122+ } ,
123+ } ) ;
124+ } ,
125+ [ ]
126+ ) ;
127+
128+ const providerConfigured = useCallback ( ( provider : string , keyType : string ) => {
129+ console . debug ( "[useTelemetry] providerConfigured called" , { provider, keyType } ) ;
130+ trackEvent ( {
131+ event : "provider_configured" ,
132+ properties : {
133+ provider,
134+ keyType,
135+ } ,
136+ } ) ;
137+ } , [ ] ) ;
138+
139+ const commandUsed = useCallback ( ( command : TelemetryCommandType ) => {
140+ console . debug ( "[useTelemetry] commandUsed called" , { command } ) ;
141+ trackEvent ( {
142+ event : "command_used" ,
143+ properties : {
144+ command,
145+ } ,
146+ } ) ;
147+ } , [ ] ) ;
148+
149+ const voiceTranscription = useCallback ( ( audioDurationSecs : number , success : boolean ) => {
150+ console . debug ( "[useTelemetry] voiceTranscription called" , { audioDurationSecs, success } ) ;
151+ trackEvent ( {
152+ event : "voice_transcription" ,
153+ properties : {
154+ audio_duration_b2 : roundToBase2 ( audioDurationSecs ) ,
155+ success,
59156 } ,
60157 } ) ;
61158 } , [ ] ) ;
@@ -75,6 +172,10 @@ export function useTelemetry() {
75172 workspaceSwitched,
76173 workspaceCreated,
77174 messageSent,
175+ streamCompleted,
176+ providerConfigured,
177+ commandUsed,
178+ voiceTranscription,
78179 errorOccurred,
79180 } ;
80181}
0 commit comments