Skip to content

Commit 59e1281

Browse files
committed
fix(stage-ui): simplify ttfm tracking
1 parent eedc661 commit 59e1281

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

packages/stage-ui/src/composables/use-analytics.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ export function useAnalytics() {
1212
})
1313
}
1414

15-
function trackFirstMessage(success: boolean, messageSentAt: number) {
15+
function trackFirstMessage() {
1616
// Only track the first message once
1717
if (analyticsStore.firstMessageTracked)
1818
return
1919

20+
analyticsStore.markFirstMessageTracked()
21+
2022
// Calculate time from app start to message sent
2123
const timeToFirstMessageMs = analyticsStore.appStartTime
22-
? messageSentAt - analyticsStore.appStartTime
24+
? Date.now() - analyticsStore.appStartTime
2325
: null
2426

2527
posthog.capture('first_message_sent', {
2628
time_to_first_message_ms: timeToFirstMessageMs,
27-
success,
2829
})
29-
30-
analyticsStore.markFirstMessageTracked()
3130
}
3231

3332
return {

packages/stage-ui/src/stores/chat.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ export const useChatStore = defineStore('chat', () => {
437437
}
438438
streamingMessage.value = { role: 'assistant', content: '', slices: [], tool_results: [], context: assistantContext }
439439

440-
// Capture send time for first message analytics
441-
const messageSentAt = Date.now()
440+
trackFirstMessage()
442441

443442
try {
444443
await emitBeforeMessageComposedHooks(sendingMessage)
@@ -615,14 +614,10 @@ export const useChatStore = defineStore('chat', () => {
615614
console.debug('LLM output:', fullText)
616615

617616
await emitAfterSendHooks(sendingMessage)
618-
619-
trackFirstMessage(true, messageSentAt)
620617
}
621618
catch (error) {
622619
console.error('Error sending message:', error)
623620

624-
trackFirstMessage(false, messageSentAt)
625-
626621
throw error
627622
}
628623
finally {

0 commit comments

Comments
 (0)