Skip to content

Commit d0d3581

Browse files
TheodoreSpeaksTheodore Li
andauthored
feat(posthog): Add tracking on mothership abort (#4023)
Co-authored-by: Theodore Li <theo@sim.ai>
1 parent e2d4d0e commit d0d3581

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ export function Home({ chatId }: HomeProps = {}) {
223223
posthogRef.current = posthog
224224
}, [posthog])
225225

226+
const handleStopGeneration = useCallback(() => {
227+
captureEvent(posthogRef.current, 'task_generation_aborted', {
228+
workspace_id: workspaceId,
229+
view: 'mothership',
230+
})
231+
stopGeneration()
232+
}, [stopGeneration, workspaceId])
233+
226234
const handleSubmit = useCallback(
227235
(text: string, fileAttachments?: FileAttachmentForApi[], contexts?: ChatContext[]) => {
228236
const trimmed = text.trim()
@@ -334,7 +342,7 @@ export function Home({ chatId }: HomeProps = {}) {
334342
defaultValue={initialPrompt}
335343
onSubmit={handleSubmit}
336344
isSending={isSending}
337-
onStopGeneration={stopGeneration}
345+
onStopGeneration={handleStopGeneration}
338346
userId={session?.user?.id}
339347
onContextAdd={handleContextAdd}
340348
/>
@@ -359,7 +367,7 @@ export function Home({ chatId }: HomeProps = {}) {
359367
isSending={isSending}
360368
isReconnecting={isReconnecting}
361369
onSubmit={handleSubmit}
362-
onStopGeneration={stopGeneration}
370+
onStopGeneration={handleStopGeneration}
363371
messageQueue={messageQueue}
364372
onRemoveQueuedMessage={removeFromQueue}
365373
onSendQueuedMessage={sendNow}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { memo, useCallback, useEffect, useRef, useState } from 'react'
44
import { createLogger } from '@sim/logger'
55
import { History, Plus, Square } from 'lucide-react'
66
import { useParams, useRouter } from 'next/navigation'
7+
import { usePostHog } from 'posthog-js/react'
78
import { useShallow } from 'zustand/react/shallow'
89
import {
910
BubbleChatClose,
@@ -33,6 +34,7 @@ import {
3334
import { Lock, Unlock, Upload } from '@/components/emcn/icons'
3435
import { VariableIcon } from '@/components/icons'
3536
import { useSession } from '@/lib/auth/auth-client'
37+
import { captureEvent } from '@/lib/posthog/client'
3638
import { generateWorkflowJson } from '@/lib/workflows/operations/import-export'
3739
import { ConversationListItem } from '@/app/workspace/[workspaceId]/components'
3840
import { MothershipChat } from '@/app/workspace/[workspaceId]/home/components'
@@ -101,6 +103,9 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
101103
const params = useParams()
102104
const workspaceId = propWorkspaceId ?? (params.workspaceId as string)
103105

106+
const posthog = usePostHog()
107+
const posthogRef = useRef(posthog)
108+
104109
const panelRef = useRef<HTMLElement>(null)
105110
const fileInputRef = useRef<HTMLInputElement>(null)
106111
const { activeTab, setActiveTab, panelWidth, _hasHydrated, setHasHydrated } = usePanelStore(
@@ -264,6 +269,10 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
264269
loadCopilotChats()
265270
}, [loadCopilotChats])
266271

272+
useEffect(() => {
273+
posthogRef.current = posthog
274+
}, [posthog])
275+
267276
const handleCopilotSelectChat = useCallback((chat: { id: string; title: string | null }) => {
268277
setCopilotChatId(chat.id)
269278
setCopilotChatTitle(chat.title)
@@ -394,6 +403,14 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
394403
[copilotEditQueuedMessage]
395404
)
396405

406+
const handleCopilotStopGeneration = useCallback(() => {
407+
captureEvent(posthogRef.current, 'task_generation_aborted', {
408+
workspace_id: workspaceId,
409+
view: 'copilot',
410+
})
411+
copilotStopGeneration()
412+
}, [copilotStopGeneration, workspaceId])
413+
397414
const handleCopilotSubmit = useCallback(
398415
(text: string, fileAttachments?: FileAttachmentForApi[], contexts?: ChatContext[]) => {
399416
const trimmed = text.trim()
@@ -833,7 +850,7 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
833850
isSending={copilotIsSending}
834851
isReconnecting={copilotIsReconnecting}
835852
onSubmit={handleCopilotSubmit}
836-
onStopGeneration={copilotStopGeneration}
853+
onStopGeneration={handleCopilotStopGeneration}
837854
messageQueue={copilotMessageQueue}
838855
onRemoveQueuedMessage={copilotRemoveFromQueue}
839856
onSendQueuedMessage={copilotSendNow}

apps/sim/lib/posthog/events.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ export interface PostHogEventMap {
378378
workspace_id: string
379379
}
380380

381+
task_generation_aborted: {
382+
workspace_id: string
383+
view: 'mothership' | 'copilot'
384+
}
385+
381386
task_message_sent: {
382387
workspace_id: string
383388
has_attachments: boolean

0 commit comments

Comments
 (0)