[WEB-5681] refactor: add new event trackers
Description
This PR adds new set of event trackers.
Type of Change
- [x] Improvement (change that would cause existing functionality to not work as expected)
Screenshots and Media (if applicable)
Test Scenarios
References
Summary by CodeRabbit
- Chores
- Centralized and expanded analytics/tracking across workspaces, projects, pages, work items, cycles and invitations with safer PostHog guards, workspace group context, and new backend event tracking.
- Added re-exports to surface the new tracking helpers across editions.
- New Features
- Exposes users' last login time in user profile/me responses and public types (read-only).
- Chores / Breaking
- Small public prop change: workspace delete form props expanded to include onClose.
โ๏ธ Tip: You can customize this high-level summary in your review settings.
[!NOTE] Introduces unified PostHog event tracking on backend and frontend (with workspace group context), replaces legacy trackers in key flows, and exposes user last_login_time.
- Backend:
- Event Tracking: Add
track_eventCelery task with workspace grouping and payload preprocessing inbgtasks/event_tracking_task.py; log invite/join events acrossworkspace/invite.pyandauthentication/utils/workspace_project_join.py.- User Serialization: Expose
last_login_timeinUserMeSerializerand mark read-only.- Frontend:
- New Analytics Helper: Add
helpers/event-tracker-v2.helper(CE/EE) withidentifyUser,joinWorkspaceGroup, andtrack*APIs (workspace/project/page/work item/cycle).- Provider: Update
posthog-providerto identify user and join workspace group when hydrated.- Wired Tracking: Replace legacy success trackers with new events in page create (headers, modal, list), project create, cycle create, inbox issue create, quick-add issue, issue modal create, onboarding and workspace create/delete, and invitations page.
- UX: Add error toasts where needed during page creation.
- Types:
- Add
last_login_timetoIUserinpackages/types/src/users.ts.Written by Cursor Bugbot for commit b4c40bb928e3d6f05d4802eb46373488394cd06e. This will update automatically on new commits. Configure here.
[!NOTE]
Other AI code review bot(s) detected
CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.
Walkthrough
Adds a new user field last_login_time, centralizes frontend analytics in a new event-tracker-v2 helper, and instruments backend and frontend invite/workspace/project/page/cycle/work-item flows to emit structured PostHog tracking events via a new background track_event task and frontend helpers.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
User types & serializers \packages/types/src/users.ts``, \apps/api/plane/app/serializers/user.py`` |
Added `last_login_time: string |
Backend event tracking task \apps/api/plane/bgtasks/event_tracking_task.py`` |
Replaced older auth_events API with track_event(user_id: UUID, event_name: str, slug: str, event_properties: Dict); added preprocess_data_properties() helper, workspace lookup, PostHog presence guard, normalized properties, and groups payload handling. |
Backend invite / join flows \apps/api/plane/app/views/workspace/invite.py``, \apps/api/plane/authentication/utils/workspace_project_join.py`` |
Emit track_event.delay() for user_invited_to_workspace and user_joined_workspace when creating and accepting invites (including bulk joins); removed previous standalone workspace invite event emission in acceptance path. |
Frontend centralized tracker (CE + EE re-export) \apps/web/ce/helpers/event-tracker-v2.helper.ts``, \apps/web/ee/helpers/event-tracker-v2.helper.ts`` |
New CE helper providing role mapping, identifyUser, joinWorkspaceGroup, trackEvent, and domain-specific trackers (trackWorkspaceCreated/Deleted, trackProjectCreated, trackWorkItemCreated, trackCycleCreated, trackPageCreated); EE file re-exports CE helper. |
Frontend PostHog provider \apps/web/core/lib/posthog-provider.tsx`` |
Switched to using identifyUser() and joinWorkspaceGroup() helpers and useUserProfile(); added separate effect for joining workspace group; removed inline role-derivation logic. |
Frontend: workspace lifecycle components \apps/web/core/components/workspace/``, \apps/web/core/components/onboarding/`` |
Replaced captureSuccess() with conditional trackWorkspaceCreated() / trackWorkspaceDeleted() calls; added user/workspace hooks and role derivation; expanded CreateWorkspace props; DeleteWorkspaceForm props now include onClose. |
Frontend: project/page/cycle/work-item flows \apps/web/ce/components/projects/create/root.tsx``, \apps/web/core/components/pages/``, \apps/web/core/components/cycles/modal.tsx``, \apps/web/core/components/inbox/``, \apps/web/core/components/issues/*`` |
Replaced legacy captureSuccess() with conditional v2 tracker calls (trackProjectCreated, trackPageCreated, trackCycleCreated, trackWorkItemCreated); migrated some handlers to async/await and added user/workspace guards and role resolution. |
Frontend invitations \apps/web/app/(all)/invitations/page.tsx`` |
Replaced joinEventGroup(...) with joinWorkspaceGroup(redirectWorkspace) helper and guarded call with redirectWorkspace presence. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant Frontend
participant EventHelper as Event-Tracker-V2
participant PostHog
User->>Frontend: create project/page/cycle/work-item or accept invite
Frontend->>EventHelper: identifyUser / joinWorkspaceGroup (workspace) and compute role
Frontend->>EventHelper: trackEvent / trackXCreated with role & properties
EventHelper->>PostHog: capture event and set group (workspace)
PostHog-->>EventHelper: ack
sequenceDiagram
participant Client
participant BackendAPI
participant Celery as track_event.delay
participant BGTask as event_tracking_task.track_event
participant Workspace as WorkspaceModel
participant PostHog
Client->>BackendAPI: send invite / accept invite
BackendAPI->>Celery: enqueue track_event.delay(user_id, event, slug, props)
Celery->>BGTask: execute track_event(user_id, event, slug, props)
BGTask->>Workspace: load workspace for context (slug/owner)
BGTask->>PostHog: preprocess props, include groups, capture event
PostHog-->>BGTask: ack
Estimated code review effort
๐ฏ 4 (Complex) | โฑ๏ธ ~60 minutes
- Areas needing extra attention:
apps/api/plane/bgtasks/event_tracking_task.pyโ payload preprocessing, PostHog guard, groups payload format, workspace lookup and role derivation.apps/api/plane/app/views/workspace/invite.pyandapps/api/plane/authentication/utils/workspace_project_join.pyโ correctness and timing oftrack_event.delay()calls and property shapes.apps/web/ce/helpers/event-tracker-v2.helper.tsโ role mapping edge cases, null/undefined guards, and exported API signatures.- Cross-cutting replacements of
captureSuccessโ ensure event names/properties remain consistent and no legacy telemetry remains. - Type addition
last_login_timeโ verify serializers, backend responses, and frontend types remain aligned. - Prop/API surface changes:
CreateWorkspaceprops expansion andDeleteWorkspaceForm.onCloseโ ensure all consumers updated.
Poem
๐
I hopped through lines both new and bright,
I counted invites by moonlit night,
A last-login bell, a tracked event cheer,
PostHog hums softly when rabbits are near,
Hop on โ analytics are in sight.
Pre-merge checks and finishing touches
โ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | โ ๏ธ Warning | Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
โ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | โ Passed | The title accurately summarizes the main change: adding new event trackers across the system. |
| Description check | โ Passed | Description covers key changes across backend, frontend, provider, and types with sufficient detail and references the PR objectives via a summary. Type of change is properly marked. However, 'Test Scenarios' and 'References' sections are empty. |
โจ Finishing touches
- [ ] ๐ Generate docstrings
๐งช Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
chore-event-updates
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.