feat(analytics): add PostHog product analytics#3910
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Wires PostHog event capture across the product surface: landing/signup views; settings navigation; docs/tour interactions; template usage; workspace/table/knowledge-base activity; and broad API lifecycle events (credentials, MCP, webhooks, skills/tools, A2A agents, notifications, API keys, billing/subscription changes). Adds execution-level analytics for workflows (success/failure, duration, block types) and expands a few endpoints to accept/propagate Written by Cursor Bugbot for commit 531d81f. Configure here. |
Greptile SummaryThis PR instruments 48 PostHog product analytics events across the entire Sim user journey — signup, billing, workspace/workflow lifecycle, execution, blocks, knowledge bases, tables, credentials, MCP servers, custom tools, BYOK keys, A2A agents, copilot, and settings navigation. The implementation follows a clean architecture: a typed event catalog (
Confidence Score: 5/5Safe to merge — all previously flagged P0/P1 issues are resolved, and the two remaining findings are minor P2 data-quality suggestions All critical issues from previous review rounds are resolved: workflow_created now fires after the DB transaction, auth_method is derived from the actual provider, workflow_executed is guarded against paused status, and block add/remove tracking is clarified. The new code is entirely fire-and-forget with no production risk. The two P2 items are data-quality and style improvements that don't block merge. apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx (passedKnowledgeBaseName in effect deps), apps/sim/app/workspace/[workspaceId]/home/components/template-prompts/template-prompts.tsx (double dynamic import pattern) Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser as Browser / Store
participant API as Next.js API Route
participant PH_Client as posthog-js (client)
participant PH_Server as posthog-node (server)
participant PostHog as PostHog Cloud
Note over Browser,PostHog: Client-side events (React components)
Browser->>PH_Client: usePostHog() → captureEvent(posthog, 'block_added', {...})
PH_Client-->>PostHog: batch upload (async)
Note over Browser,PostHog: Client-side events (Zustand stores)
Browser->>Browser: import('@/lib/posthog/client')
Browser->>PH_Client: captureClientEvent('block_added', {...})
PH_Client-->>PostHog: batch upload (async)
Note over API,PostHog: Server-side events (API routes)
API->>API: captureServerEvent(userId, 'workflow_executed', props, options)
API->>PH_Server: client.capture({ distinctId, event, properties: { ...props, $groups, $set_once } })
PH_Server-->>PostHog: flush (flushAt=20 or flushInterval=10s)
Note over API,PostHog: Graceful shutdown
API->>PH_Server: getPostHogClient()?.shutdown()
PH_Server-->>PostHog: flush remaining events
Reviews (10): Last reviewed commit: "fix(analytics): fix posthog in useCallba..." | Re-trigger Greptile |
…ed executions, enterprise cancellation, settings double-fire
|
@greptile |
|
@cursor review |
apps/sim/app/workspace/[workspaceId]/settings/[section]/settings.tsx
Outdated
Show resolved
Hide resolved
|
@greptile |
|
@cursor review |
…tring workspace groups
apps/sim/app/workspace/[workspaceId]/home/components/template-prompts/template-prompts.tsx
Outdated
Show resolved
Hide resolved
… chat phantom workspace group
|
@greptile |
|
@cursor review |
apps/sim/app/api/workflows/[id]/executions/[executionId]/cancel/route.ts
Show resolved
Hide resolved
…aceId shadow in catch block
|
@cursor review |
…port to avoid stale closure
|
@greptile |
|
@cursor review |
…duplicate copilot_panel_opened
…copilot_panel_opened
…nd lifecycle events
|
Latest push adds:
All server events are fire-and-forget (posthog-node queues internally). Client events use |
|
@greptile |
|
@cursor review |
apps/sim/app/workspace/[workspaceId]/components/product-tour/use-tour.ts
Show resolved
Hide resolved
… for bulk operations
|
@greptile |
|
@cursor review |
* feat(analytics): add PostHog product analytics * fix(posthog): fix workspace group via URL params, type errors, and clean up comments * fix(posthog): address PR review - fix pre-tx event, auth_method, paused executions, enterprise cancellation, settings double-fire * chore(posthog): remove unused identifyServerPerson * fix(posthog): isolate processQueuedResumes errors, simplify settings posthog deps * fix(posthog): correctly classify SSO auth_method, fix phantom empty-string workspace groups * fix(posthog): remove usePostHog from memo'd TemplateCard, fix copilot chat phantom workspace group * fix(posthog): eliminate all remaining phantom empty-string workspace groups * fix(posthog): fix cancel route phantom group, remove redundant workspaceId shadow in catch block * fix(posthog): use ids.length for block_removed guard to handle container blocks with descendants * chore(posthog): remove unused removedBlockTypes variable * fix(posthog): remove phantom $set person properties from subscription events * fix(posthog): add passedKnowledgeBaseName to knowledge_base_opened effect deps * fix(posthog): capture currentWorkflowId synchronously before async import to avoid stale closure * fix(posthog): add typed captureEvent wrapper for React components, deduplicate copilot_panel_opened * feat(posthog): add task_created and task_message_sent events, remove copilot_panel_opened * feat(posthog): track task_renamed, task_deleted, task_marked_read, task_marked_unread * feat(analytics): expand posthog event coverage with source tracking and lifecycle events * fix(analytics): flush posthog events on SIGTERM before ECS task termination * fix(analytics): fix posthog in useCallback deps and fire block events for bulk operations
Summary
lib/posthog/events.ts) as single source of truth for all event names and property shapeslib/posthog/server.ts) with fire-and-forgetcaptureServerEvent— no latency impact, graceful no-op when PostHog is disabledlib/posthog/client.ts) for Zustand stores using dynamic import patterngroups: { workspace }) for workspace-level PostHog queries$set_onceactivation milestones (e.g.first_execution_at,first_workflow_created_at) for cohort analysis$setperson properties on billing events to track plan stateapi_key_createdsource (settingsvsdeploy_modal) to understand where users discover API keysType of Change
Testing
Tested manually — verified events appear in PostHog Live Events for workflow execution, block add/remove, settings navigation, knowledge base open, and message sent.
Checklist