Skip to content

feat(analytics): posthog audit — remove noise, add 10 new events#3917

Merged
waleedlatif1 merged 4 commits intostagingfrom
analytics/posthog-audit
Apr 3, 2026
Merged

feat(analytics): posthog audit — remove noise, add 10 new events#3917
waleedlatif1 merged 4 commits intostagingfrom
analytics/posthog-audit

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Remove task_marked_read event (fires automatically on view, not a meaningful user action)
  • Add workspace_id to task_message_sent for proper group analytics attribution
  • Add 9 new high-value events: search_result_selected, workflow_imported, workflow_exported, folder_created, folder_deleted, logs_filter_applied, knowledge_base_document_deleted, scheduled_task_created, scheduled_task_deleted
  • Fix search modal: tables/files/knowledge bases were incorrectly reporting result_type: 'task' — now use correct types

Type of Change

  • Improvement (analytics coverage and accuracy)

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Remove task_marked_read (fires automatically on every task view).

Add workspace_id to task_message_sent for group analytics.

New events:
- search_result_selected: block/tool/trigger/workflow/table/file/
  knowledge_base/workspace/task/page/docs with query_length
- workflow_imported: count + format (json/zip)
- workflow_exported: count + format (json/zip)
- folder_created / folder_deleted
- logs_filter_applied: status/workflow/folder/trigger/time
- knowledge_base_document_deleted
- scheduled_task_created / scheduled_task_deleted
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 3, 2026 9:32pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 3, 2026

PR Summary

Low Risk
Mostly adds/removes PostHog capture calls and updates the typed event catalog; primary risk is incorrect event properties/group attribution causing analytics noise or runtime type mismatches, not product behavior changes.

Overview
Adds new PostHog instrumentation across folders, schedules, knowledge-base documents, workflow import/export, logs filtering, and sidebar search result selection, generally attaching workspace_id and PostHog group context for workspace-level analytics.

Removes the noisy task_marked_read event and updates task_message_sent to include workspace_id. Also fixes search modal analytics so tables/files/knowledge bases emit distinct result_type values instead of being reported as task, and extends PostHogEventMap with the new event/property schemas.

Reviewed by Cursor Bugbot for commit 728fa7b. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR performs a focused PostHog analytics audit: it removes the noisy task_marked_read event (which fired automatically on every view), adds workspace_id to task_message_sent for proper group attribution, fixes the search modal where tables/files/knowledge bases were all misreporting as result_type: 'task', and introduces 9 new high-value events (search_result_selected, workflow_imported, workflow_exported, folder_created, folder_deleted, logs_filter_applied, knowledge_base_document_deleted, scheduled_task_created, scheduled_task_deleted).

Key changes:

  • All new client-side events correctly use usePostHog() + a posthogRef + captureEvent, consistent with the rest of the codebase (the previous P1 concern about captureClientEvent in hooks has been resolved)
  • Server-side events use captureServerEvent with { groups: { workspace } } for PostHog group analytics; workspaceId-nullable paths defensively fall back to '' and omit the groups option
  • The logs_filter_applied event correctly fires only on user interaction (not on initial state hydration), and the time-range path handles both preset ranges and custom date ranges without double-firing
  • The format field in workflow_imported accurately mirrors the actual import code path: 'zip' is only reported when a single zip file is processed, matching the if (hasZip && fileArray.length === 1) branch in the import logic
  • Search modal now has dedicated per-type handlers (handleTableSelect, handleFileSelect, handleKbSelect) with correct result_type values, fixing the long-standing misclassification bug

Confidence Score: 5/5

This PR is safe to merge — all changes are additive analytics instrumentation with no impact on business logic or data flow

No P0 or P1 issues found. All new client-side events use the correct usePostHog() + posthogRef + captureEvent pattern (the prior P1 concern is resolved). Server-side events are placed after successful operations, have proper defensive fallbacks for nullable workspaceId, and include group attribution. The search modal result_type bug fix is accurate. No logic, auth, or data-integrity concerns introduced.

No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/posthog/events.ts Removes task_marked_read, adds workspace_id to task_message_sent, and adds 9 new strongly-typed event definitions with correct field shapes
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx Fixes the result_type bug for tables/files/knowledge bases (all previously used handleTaskSelect), adds per-type handler callbacks with correct result_type values, and tracks query_length via deferredSearchRef
apps/sim/app/workspace/[workspaceId]/logs/components/logs-toolbar/logs-toolbar.tsx Wraps five filter setters in new handler callbacks that also fire logs_filter_applied with the correct filter_type; uses usePostHog() + posthogRef pattern consistently
apps/sim/app/workspace/[workspaceId]/w/hooks/use-import-workflow.ts Adds workflow_imported event after successful import; format detection correctly mirrors the actual import code path (zip only when fileArray.length === 1); uses usePostHog() + posthogRef pattern
apps/sim/app/workspace/[workspaceId]/w/hooks/use-export-workflow.ts Adds workflow_exported event with workflow_count and format fields; uses usePostHog() + posthogRef pattern consistent with the rest of the codebase
apps/sim/app/api/mothership/chats/[chatId]/route.ts Removes the task_marked_read event (fires on automatic view, not a meaningful user action), preserving only task_marked_unread

Reviews (3): Last reviewed commit: "fix(analytics): correct format field log..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 728fa7b. Configure here.

@waleedlatif1 waleedlatif1 merged commit b744cd2 into staging Apr 3, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the analytics/posthog-audit branch April 3, 2026 21:39
abhinavDhulipala pushed a commit to abhinavDhulipala/sim that referenced this pull request Apr 4, 2026
…studioai#3917)

* feat(analytics): posthog audit — remove noise, add 10 new events

Remove task_marked_read (fires automatically on every task view).

Add workspace_id to task_message_sent for group analytics.

New events:
- search_result_selected: block/tool/trigger/workflow/table/file/
  knowledge_base/workspace/task/page/docs with query_length
- workflow_imported: count + format (json/zip)
- workflow_exported: count + format (json/zip)
- folder_created / folder_deleted
- logs_filter_applied: status/workflow/folder/trigger/time
- knowledge_base_document_deleted
- scheduled_task_created / scheduled_task_deleted

* fix(analytics): use usePostHog + captureEvent in hooks, track custom date range

* fix(analytics): always fire scheduled_task_deleted regardless of workspaceId

* fix(analytics): correct format field logic and add missing useCallback deps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant