Skip to content

Commit 7ecfd2c

Browse files
committed
fix(analytics): use usePostHog + captureEvent in hooks, track custom date range
1 parent 76eee93 commit 7ecfd2c

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

apps/sim/app/workspace/[workspaceId]/logs/components/logs-toolbar/logs-toolbar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,12 @@ export const LogsToolbar = memo(function LogsToolbar({
406406
(start: string, end: string) => {
407407
setDateRange(start, end)
408408
setDatePickerOpen(false)
409+
captureEvent(posthogRef.current, 'logs_filter_applied', {
410+
filter_type: 'time',
411+
workspace_id: workspaceId,
412+
})
409413
},
410-
[setDateRange]
414+
[setDateRange, workspaceId]
411415
)
412416

413417
/**

apps/sim/app/workspace/[workspaceId]/w/hooks/use-export-workflow.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useCallback, useRef, useState } from 'react'
22
import { createLogger } from '@sim/logger'
33
import { useParams } from 'next/navigation'
4-
import { captureClientEvent } from '@/lib/posthog/client'
4+
import { usePostHog } from 'posthog-js/react'
5+
import { captureEvent } from '@/lib/posthog/client'
56
import {
67
downloadFile,
78
exportWorkflowsToZip,
@@ -28,13 +29,17 @@ export function useExportWorkflow({ onSuccess }: UseExportWorkflowProps = {}) {
2829
const [isExporting, setIsExporting] = useState(false)
2930
const params = useParams()
3031
const workspaceId = params.workspaceId as string | undefined
32+
const posthog = usePostHog()
3133

3234
const onSuccessRef = useRef(onSuccess)
3335
onSuccessRef.current = onSuccess
3436

3537
const workspaceIdRef = useRef(workspaceId)
3638
workspaceIdRef.current = workspaceId
3739

40+
const posthogRef = useRef(posthog)
41+
posthogRef.current = posthog
42+
3843
/**
3944
* Export the workflow(s) to JSON or ZIP
4045
* - Single workflow: exports as JSON file
@@ -101,7 +106,7 @@ export function useExportWorkflow({ onSuccess }: UseExportWorkflowProps = {}) {
101106
const { clearSelection } = useFolderStore.getState()
102107
clearSelection()
103108

104-
captureClientEvent('workflow_exported', {
109+
captureEvent(posthogRef.current, 'workflow_exported', {
105110
workspace_id: workspaceIdRef.current ?? '',
106111
workflow_count: exportedWorkflows.length,
107112
format: exportedWorkflows.length === 1 ? 'json' : 'zip',

apps/sim/app/workspace/[workspaceId]/w/hooks/use-import-workflow.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useCallback, useState } from 'react'
1+
import { useCallback, useRef, useState } from 'react'
22
import { createLogger } from '@sim/logger'
33
import { useQueryClient } from '@tanstack/react-query'
44
import { useRouter } from 'next/navigation'
5-
import { captureClientEvent } from '@/lib/posthog/client'
5+
import { usePostHog } from 'posthog-js/react'
6+
import { captureEvent } from '@/lib/posthog/client'
67
import {
78
extractWorkflowsFromFiles,
89
extractWorkflowsFromZip,
@@ -37,6 +38,9 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
3738
const queryClient = useQueryClient()
3839
const createFolderMutation = useCreateFolder()
3940
const clearDiff = useWorkflowDiffStore((state) => state.clearDiff)
41+
const posthog = usePostHog()
42+
const posthogRef = useRef(posthog)
43+
posthogRef.current = posthog
4044
const [isImporting, setIsImporting] = useState(false)
4145

4246
/**
@@ -205,7 +209,7 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
205209
logger.info(`Import complete. Imported ${importedWorkflowIds.length} workflow(s)`)
206210

207211
if (importedWorkflowIds.length > 0) {
208-
captureClientEvent('workflow_imported', {
212+
captureEvent(posthogRef.current, 'workflow_imported', {
209213
workspace_id: workspaceId,
210214
workflow_count: importedWorkflowIds.length,
211215
format: hasZip ? 'zip' : 'json',

0 commit comments

Comments
 (0)