feat(analytics): tag discuss-launched task events with signal_report_id#2369
Merged
andrewm4894 merged 4 commits intoMay 27, 2026
Merged
Conversation
When a user starts a chat from an inbox report via the Discuss button, the task and task run already record the report ID on the backend, but the analytics events did not — so it was not possible to filter PostHog events down to a single discuss-launched session. This adds `signal_report_id` to: - `TASK_CREATED` (both call sites: useDiscussReport and useTaskCreation), so the event that opens the session is directly tagged. - All subsequent events fired while the user is viewing the task, via a PostHog super-property registered through `setActiveTaskAnalyticsContext` on navigation. The property is set when entering a task-detail view whose task has `signal_report` populated, and cleared when navigating elsewhere (including via goBack/goForward). Caveat: background events for non-active tasks (e.g. `AGENT_FILE_ACTIVITY` firing while the user is on the inbox) won't pick up the super-property. Threading the report ID through SessionService directly would cover that, but it's substantially more invasive and can be done later if needed. Generated-By: PostHog Code Task-Id: d9940e39-a843-4018-ace7-be597fd964cd
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/stores/navigationStore.test.ts:19-22
**New behavior not tested**
`setActiveTaskAnalyticsContext` was added to the mock to prevent import errors, but no test cases were added to verify it is actually called — or called with the right argument — when navigating to/from a task that has `signal_report` set. Without these tests, a future refactor could silently stop tagging events and the suite would still pass. Consider adding a parameterised test that: (1) navigates to a task whose `signal_report` is populated and asserts `setActiveTaskAnalyticsContext` was called with that task, and (2) navigates back/away and asserts it was called with `null`.
### Issue 2 of 2
apps/code/src/renderer/utils/analytics.ts:160-170
**Stale super-property on cold start**
`posthog.register` persists super-properties to local storage, so `signal_report_id` survives an app restart. On the next launch, the store is rehydrated from persisted state before `hydrateTask` calls `navigateToTask` (which eventually re-invokes `setActiveTaskAnalyticsContext`). Events fired in that window — e.g. the initial `TASK_VIEWED` call or any session-level captures — would carry the `signal_report_id` from the previous session. The gap is small in practice, but worth a call to `posthog.unregister("signal_report_id")` during `initializePostHog` so the slate is always clean at startup.
Reviews (1): Last reviewed commit: "feat(analytics): tag discuss-launched ta..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06453d4c96
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
PostHog persists super-properties to local storage, so `signal_report_id` registered by `setActiveTaskAnalyticsContext` during one session would survive an app restart. Events fired on next launch — before navigation re-applies the current task's context — could carry a stale ID from the previous session. Unregister `signal_report_id` inside `initializePostHog` so every cold start begins with a clean slate. The helper still re-registers it when the user lands on a discuss-launched task. Addresses Greptile P2 review feedback on #2369. Generated-By: PostHog Code Task-Id: d9940e39-a843-4018-ace7-be597fd964cd
…uss-session-events-with-report-id # Conflicts: # apps/code/src/renderer/utils/analytics.ts
Thread the inbox report UUID into configureEnvironment so it is emitted as an x-posthog-property-signal_report_id header. The PostHog LLM gateway lifts it onto the $ai_generation events the agent produces, so a discuss- launched session's LLM traffic is tagged at source (Anthropic path only). Renderer events were already tagged via the super-property in #2369; this covers the agent/gateway-emitted events that the renderer cannot reach.
Twixes
approved these changes
May 27, 2026
Gilbert09
added a commit
that referenced
this pull request
May 28, 2026
Mirror desktop's inbox event names + property shapes on the mobile app so both clients are comparable in PostHog dashboards. Events wired: - `Inbox viewed` — fired once per inbox-tab focus, with priority/actionability breakdown counts (per #2295). - `Inbox report opened` / `closed` / `scrolled` — fired from the report detail screen via a new `useInboxEngagementTracker` hook, with priority + actionability snapshotted at open time. - `Inbox report action` — fired for: - Dismiss / snooze via the dismiss sheet (with `dismissal_reason` and `dismissal_note`, truncated to 1000 chars per #2287). - "Start task" on the detail screen → `create_pr`, surface `detail_pane`. - Tinder swipe-right (accept) → `create_pr`, surface `list_row`. - Tinder swipe-left (dismiss) → `dismiss`, surface `list_row`. - Expanding the Signals list on the detail screen → `expand_signal`. For #2369 (tagging discuss-launched task events with `signal_report_id`): the task detail screen registers a `signal_report_id` PostHog super-property for the duration of the screen when the task carries one, matching the desktop super-property behaviour. #2380 (`Signal source connected`) is intentionally skipped: there is no signal-source connect / data-source-setup flow in the mobile app. We do not fire any "Task created" event on mobile yet, so the desktop-side `Task created` tagging in #2369 also doesn't apply here — only the super-property half does, and that's what we wired. Architecture: analytics types and the `useAnalytics()` / `useActiveTaskAnalyticsContext()` hooks live in `apps/mobile/src/lib/analytics.ts`. Event names and property shapes are literal mirrors of `apps/code/src/shared/types/analytics.ts` — no shared package extraction since the desktop types live inside `apps/code`, not in a shared workspace. Tests: - `apps/mobile/src/lib/analytics.test.ts` — `computeReportAgeHours` and the `useActiveTaskAnalyticsContext` super-property lifecycle. - `apps/mobile/src/features/inbox/utils.test.ts` — `buildInboxViewedProperties` (priority/actionability counts, has_active_filters detection). - `apps/mobile/src/features/inbox/hooks/useInboxEngagementTracker.test.ts` — OPENED/CLOSED/SCROLLED lifecycle, scroll-once semantics, and signalAction inheritance vs. overrides. `pnpm --filter @posthog/mobile test` → 119 passed (14 new). `pnpm lint` clean. No new TypeScript errors. Generated-By: PostHog Code Task-Id: 2e652fec-af01-4476-b6cf-ab9b4de015db
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tags discuss-launched sessions with
signal_report_idso a session's PostHog events can be filtered down to a single inbox report.Task createdis tagged at both call sites; a super-property (setActiveTaskAnalyticsContext) tags the rest of the in-task renderer events and is cleared on navigation away.configureEnvironmentforwardsx-posthog-property-signal_report_id, which the gateway lifts onto$ai_generationevents. No posthog-repo change needed — the gateway already lifts arbitraryx-posthog-property-*headers.Caveat
Only the Anthropic path forwards the header (
ANTHROPIC_CUSTOM_HEADERS); OpenAI/codex models won't be tagged.Test plan
x-posthog-property-task_idonto$ai_generation(the same path this PR addssignal_report_idto)$ai_generationcarryingsignal_report_id— verify post-deploy; discuss runs a prebuilt sandbox agent, so it isn't locally testable