From 38f12e8df400b2dba8c4bf38b61bb3896720ab10 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Mon, 1 Jun 2026 23:29:28 -0700 Subject: [PATCH] Track parallel work education telemetry (#4449) Co-authored-by: Orca --- docs/reference/README.md | 3 +- .../new-user-parallel-work-telemetry.md | 245 ++++++++++++++++++ src/main/runtime/orca-runtime.ts | 52 ++-- src/main/runtime/rpc/methods/terminal.ts | 7 +- src/main/runtime/rpc/schemas.test.ts | 13 + .../window/attach-main-window-services.ts | 8 +- src/preload/api-types.ts | 3 + src/preload/index.ts | 5 + src/renderer/src/App.tsx | 2 + src/renderer/src/assets/main.css | 25 ++ .../ContextualTourOverlay.tsx | 24 +- .../contextual-tour-step-actions.ts | 4 +- .../settings/SettingsSetupGuideCard.tsx | 7 +- .../setup-guide/SetupGuideModal.tsx | 14 + .../SetupGuideTelemetryObserver.tsx | 15 ++ .../use-setup-guide-telemetry.test.ts | 117 +++++++++ .../setup-guide/use-setup-guide-telemetry.ts | 178 +++++++++++++ .../sidebar/SetupGuideSidebarEntry.tsx | 7 +- .../src/components/sidebar/SidebarToolbar.tsx | 4 +- .../components/terminal-pane/TerminalPane.tsx | 2 +- .../terminal-pane/keyboard-handlers.ts | 29 ++- .../use-terminal-pane-context-menu.ts | 29 ++- .../use-terminal-pane-lifecycle.ts | 21 +- src/renderer/src/constants/terminal.ts | 4 + src/renderer/src/hooks/useIpcEvents.test.ts | 7 +- src/renderer/src/hooks/useIpcEvents.ts | 21 +- .../lib/feature-education-telemetry.test.ts | 208 +++++++++++++++ .../src/lib/feature-education-telemetry.ts | 212 ++++++++++++++- .../src/runtime/web-runtime-session.test.ts | 108 +++++++- .../src/runtime/web-runtime-session.ts | 95 ++++++- .../feature-education-telemetry.test.ts | 10 +- src/shared/feature-education-telemetry.ts | 25 ++ src/shared/feature-wall-setup-steps.ts | 7 + ...telemetry-events-feature-education.test.ts | 22 ++ src/shared/telemetry-events.ts | 78 +++++- 35 files changed, 1548 insertions(+), 63 deletions(-) create mode 100644 docs/reference/new-user-parallel-work-telemetry.md create mode 100644 src/renderer/src/components/setup-guide/SetupGuideTelemetryObserver.tsx create mode 100644 src/renderer/src/components/setup-guide/use-setup-guide-telemetry.test.ts create mode 100644 src/renderer/src/components/setup-guide/use-setup-guide-telemetry.ts create mode 100644 src/renderer/src/lib/feature-education-telemetry.test.ts diff --git a/docs/reference/README.md b/docs/reference/README.md index 0f33294e8..01261abed 100644 --- a/docs/reference/README.md +++ b/docs/reference/README.md @@ -9,7 +9,8 @@ Keep this folder for versioned reference docs that are meant to survive past a s - Docs that other checked-in files link to. - Telemetry availability notes that dashboard authors need after the original design or implementation branch is gone. See [Telemetry Availability](./telemetry-availability.md). - Feature education state, interaction tracking, and retention analytics notes that define how contextual tours are persisted and measured. See [Feature Education State](./feature-education-state.md), [Feature Discovery Interaction Tracking](./feature-discovery-interaction-tracking.md), and [Feature Education Retention Analytics](./feature-education-retention-analytics.md). +- New-user parallel work telemetry notes that define how the parallel-work tour and setup guide should be measured against retention. See [New User Parallel Work Telemetry](./new-user-parallel-work-telemetry.md). ## What Stays Out -Ephemeral design notes, implementation sketches, and planning docs should stay as local Markdown files under `docs/`. They are ignored by default so they do not get checked in accidentally. \ No newline at end of file +Ephemeral design notes, implementation sketches, and planning docs should stay as local Markdown files under `docs/`. They are ignored by default so they do not get checked in accidentally. diff --git a/docs/reference/new-user-parallel-work-telemetry.md b/docs/reference/new-user-parallel-work-telemetry.md new file mode 100644 index 000000000..03d77fbdb --- /dev/null +++ b/docs/reference/new-user-parallel-work-telemetry.md @@ -0,0 +1,245 @@ +# New User Parallel Work Telemetry + +## Goal + +Measure whether the new parallel-work tours and the eight-step `Getting started` flow improve new-user activation and retention. + +The product question is not "did the tour render?" It is: + +- Did users who were eligible for the new parallel-work education retain better at D1, D3, and D7? +- Did seeing or completing the tour increase the behaviors that the activation plan expects: terminal splits, two agents in one worktree, two worktrees within 72 hours, task/review source use, setup script configuration, notifications, and agent capability setup? +- Where do users leave the education flow: before the tour starts, during a tour, after skipping a tour, after opening `Getting started`, or partway through the eight setup steps? + +This document implements the telemetry portion of [`new-user-parallel-work-activation.md`](./new-user-parallel-work-activation.md). + +Validation mode: the current branch logs the would-be event name and payload to the console instead of sending these new feature-education events through product telemetry. Keep the logged payload shape identical to the event payloads below so reviewers can verify what would be emitted before product telemetry is re-enabled. + +## Product Decisions + +Question: Should Orca keep, revise, or disable the automatic `workspace-agent-sessions` tour for new users? + +Decision owner/use: Product and growth review the retention and activation read after rollout. If exposed users retain and activate better than eligible-but-unexposed users, keep or expand the tour. If exposed users underperform or skip/cancel heavily, revise copy, timing, or gating. + +Question: Which part of the education flow is weak? + +Decision owner/use: If users usually stop on a specific tour step, revise that step or shorten the tour. If users complete the tour but do not progress through `Getting started`, improve the handoff. If users open `Getting started` but stall before the first two parallel-work steps, revise the checklist actions. + +Dashboard: `New User Parallel Work Activation` + +Action: Use the dashboard to decide whether to continue rollout, adjust the tour, reorder checklist steps, or add missing downstream action telemetry. + +## Existing Telemetry To Reuse + +Keep the existing contextual-tour events as the primary tour exposure and outcome contract: + +- `contextual_tour_shown` +- `contextual_tour_outcome` + +`contextual_tour_outcome` already carries: + +- `tour_id` +- `source` +- `outcome`: `completed`, `skipped`, or `cancelled` +- `steps_seen` +- `total_steps` + +For the current branch, `workspace-agent-sessions` is the activation tour. Its source should distinguish automatic first-workspace exposure from checklist-triggered education: + +- `workspace_agent_sessions_visible` for automatic surface-driven tour exposure +- `setup_guide_parallel_work` for the explicit checklist `Try it out` path + +Do not add one telemetry event per tour opportunity or step render. Opportunity checks are driven by local UI eligibility, retries, target visibility, modal state, and session guards; emitting every "not shown" reason would turn tour gating into passive eligibility telemetry. One shown event plus one outcome event keeps volume low and still answers whether users saw, skipped, cancelled, completed, and how far they got. + +## Tour Depth Improvement + +Add stable step-depth fields to `contextual_tour_outcome` so the analysis can tell whether a user reached the actual late steps, not only how many visible steps happened to render. + +Additive schema fields: + +- `furthest_step_index`: integer `1..8` +- `defined_step_count`: integer `1..8` + +Keep `steps_seen` and `total_steps`: + +- `steps_seen` remains the count of unique rendered visible steps. +- `total_steps` remains the visible-step denominator for the user session. +- `furthest_step_index` is the highest 1-based index from the tour definition reached by the user. +- `defined_step_count` is the number of steps defined for that tour, regardless of target skipping. + +This handles target-skipping correctly. A user who sees tour steps 1, 4, and 5 should report `steps_seen: 3`, `total_steps: 3`, `furthest_step_index: 5`, and `defined_step_count: 5`. + +## New Setup Guide Events + +The eight `Getting started` steps need a small telemetry contract because they are not contextual-tour steps. They are durable activation milestones. + +### `setup_guide_opened` + +Emit once when the modal opens. + +Payload: + +- `source`: `sidebar`, `contextual_tour`, `settings`, `feature_wall`, `help_menu`, or `unknown` +- `initial_completed_count`: integer `0..8` +- `total_steps`: integer `8` +- `first_incomplete_step_id`: one of the eight setup step ids, or `none` + +Use: + +- Measures whether users reach the checklist after the tour. +- Establishes starting depth so existing progress does not look like checklist-driven progress. + +### `setup_guide_closed` + +Emit once when a shown setup guide closes or unmounts. + +Payload: + +- `source`: same value used by `setup_guide_opened` +- `outcome`: `completed`, `dismissed`, or `interrupted` +- `initial_completed_count`: integer `0..8` +- `final_completed_count`: integer `0..8` +- `total_steps`: integer `8` +- `active_step_id`: one of the eight setup step ids, or `none` + +Use: + +- Measures whether users treat the checklist as useful or dismiss it without progress. +- Gives a compact "how far through the 8 steps" read without uploading a progress snapshot on every render. + +### `setup_guide_step_completed` + +Emit once per setup step when that step first transitions from incomplete to complete while the setup guide is visible. Hidden/background progress is persisted locally as baseline state but not emitted, because async setup refresh cannot reliably distinguish old completions from new user action. + +Payload: + +- `step_id`: one of `split-terminal`, `two-worktrees`, `notifications`, `default-agent`, `task-sources`, `setup-script`, `add-two-repos`, `agent-capabilities` +- `section_id`: `parallel-work` or `setup` +- `completed_count`: integer `1..8` +- `total_steps`: integer `8` +- `setup_guide_visible`: boolean + +Use: + +- Measures the in-guide depth through the eight steps without backfilling old setup state on launch. +- Lets retention analysis bucket users by `0`, `1`, `2`, `3-4`, `5-7`, and `8` completed setup steps. + +Implementation detail: persist a local set of emitted setup-guide step ids, similar in spirit to `contextualToursSeenIds`, so inferred durable state does not re-emit on every launch. Do not upload that local set. + +## Downstream Activation Events + +Reuse existing downstream events whenever possible: + +- `workspace_created` for worktree/workspace creation depth +- `agent_started` for agent activity and follow-up actions +- `settings_changed` for supported settings such as notifications +- setup script prompt events for setup-script configuration paths +- task/source-specific events where they already exist + +Add action-specific downstream telemetry only when the retention question cannot be answered from existing events. The first likely gap is terminal splitting. The activation plan names first-session terminal split as a primary success criterion, but the branch currently records `terminal-pane-split` as local feature-interaction state, not product telemetry. + +If no existing telemetry captures terminal split, add: + +### `terminal_pane_split` + +Emit when a split succeeds, capped to the first split for each `source` + `direction` pair per UTC day on the local profile. This keeps the event useful for activation cohorts without making heavy terminal users dominate telemetry volume. + +Payload: + +- `source`: `contextual_tour`, `keyboard`, `context_menu`, `command`, `unknown` +- `direction`: `vertical` or `horizontal` + +Do not include pane ids, worktree ids, paths, commands, prompts, repo names, branch names, hostnames, or terminal content. + +## Retention Analysis + +Use new-user eligibility as the least-biased baseline: + +1. Eligible baseline: new-user cohorts represented by first-run/onboarding events rather than uploading local tour eligibility state. +2. Exposed cohort: users with `contextual_tour_shown` where `tour_id = workspace-agent-sessions`. +3. Tour outcome cohorts: users with `contextual_tour_outcome` broken down by `outcome`. +4. Tour depth cohorts: `furthest_step_index / defined_step_count` and `steps_seen / total_steps`. +5. Checklist depth cohorts: latest `setup_guide_step_completed.completed_count`, bucketed as `0`, `1`, `2`, `3-4`, `5-7`, and `8`. + +Primary retention read: + +- D1, D3, and D7 return to `app_opened` +- Compare new-user baseline, shown, completed, skipped, cancelled, and checklist-depth cohorts + +Primary activation read: + +- terminal split in first workspace session +- two agent sessions in one worktree +- two worktrees within 72 hours +- follow-up/manual agent action +- task/review source use +- setup script configured +- notifications configured +- agent capabilities completed + +Interpretation rules: + +- A completed tour with no downstream activation means the tour is educational but not converting. +- A skipped tour with strong downstream activation means the feature may be discoverable without the tour. +- A high cancelled rate usually points to target loss, modal conflicts, or timing problems. +- Strong checklist-depth retention with weak tour retention means the checklist is the value driver, not the automatic tour. + +## Volume Estimate + +Telemetry volume estimate: + +- Trigger: contextual tour shown/outcome, setup guide open/close, setup step first completion, optional terminal split +- Expected events/user/day: 2-6 for new users who encounter the flow +- Max events/user/day: about 14 on a heavy first day: 2 tour events, 2 setup guide events, 8 setup step completions, 1-2 split events +- At 1,000 DAU: expected 2,000-6,000 events/day +- Monthly at 1,000 DAU: expected 60,000-180,000 events/month +- Approval note: The events answer the rollout decision directly and are bounded by explicit user actions or one-time durable setup completions. There are no timers, render-loop events, polling snapshots, or passive heartbeats. + +If observed volume exceeds expectation, remove or sample `setup_guide_opened` / `setup_guide_closed` before removing completion events. Completion events are the durable activation-depth read. + +## Privacy + +All payloads must be low-cardinality and schema-bounded. + +Never include: + +- prompts +- terminal commands +- paths +- URLs +- hostnames +- repo names +- branch names +- task titles +- user-authored text +- raw errors +- tokens +- pane ids, worktree ids, repo ids, or other persistent product identifiers + +## Implementation Plan + +1. Extend `contextual_tour_outcome` schema in `src/shared/telemetry-events.ts` with optional `furthest_step_index` and `defined_step_count`. +2. Track the highest reached defined tour step in `ContextualTourOverlay.tsx` alongside the existing `steps_seen` set. +3. Add setup-guide event schemas and bounded enums in `src/shared/telemetry-events.ts`. +4. Add a setup-guide telemetry helper in `src/renderer/src/lib/feature-education-telemetry.ts` or a dedicated setup-guide telemetry module. +5. Emit `setup_guide_opened` and `setup_guide_closed` from `SetupGuideModal.tsx`. +6. Emit `setup_guide_step_completed` from a small hook that observes visible setup-guide progress transitions, persists emitted step ids locally, and ignores hidden/background completions except as local baseline state. +7. Add `terminal_pane_split` only if no existing telemetry captures successful terminal splits. +8. Add schema tests for accepted payloads, rejected raw strings, count bounds, and enum bounds. +9. Add renderer tests that prove each modal open emits one open event, each close emits one close event, each step completion emits once, rerenders do not re-emit, and pre-completed persisted steps are not backfilled repeatedly. + +## Dashboard Tiles + +Create a PostHog dashboard named `New User Parallel Work Activation`. + +Tiles: + +- Tour exposure: `contextual_tour_shown` by `tour_id` and `source` +- Tour outcome: `contextual_tour_outcome` by `outcome` +- Tour depth: median `furthest_step_index / defined_step_count` +- Setup guide reach: `setup_guide_opened` by `source` +- Setup guide close outcome: `setup_guide_closed` by `outcome` +- Eight-step depth: latest `setup_guide_step_completed.completed_count` bucket +- Activation funnel: tour shown -> tour outcome -> setup guide opened -> first two setup steps complete -> D1/D3/D7 return +- Downstream actions: tour shown -> terminal split -> two agents in one worktree -> two worktrees within 72 hours + +Do not publish dashboard tiles that require raw user content or identifiers. diff --git a/src/main/runtime/orca-runtime.ts b/src/main/runtime/orca-runtime.ts index 9365c6600..db06d1484 100644 --- a/src/main/runtime/orca-runtime.ts +++ b/src/main/runtime/orca-runtime.ts @@ -71,6 +71,7 @@ import type { WorkspaceCreateTelemetrySource } from '../../shared/types' import type { FeatureInteractionId } from '../../shared/feature-interactions' +import type { TerminalPaneSplitSource } from '../../shared/feature-education-telemetry' import { FOLDER_WORKSPACE_INSTANCE_SEPARATOR, splitWorktreeId } from '../../shared/worktree-id' import { isFolderRepo } from '../../shared/repo-kind' import { getNextProjectGroupOrder } from '../../shared/project-groups' @@ -735,6 +736,7 @@ type RuntimeNotifier = { leafId?: string splitFromLeafId?: string splitDirection?: 'horizontal' | 'vertical' + splitTelemetrySource?: TerminalPaneSplitSource } ): | Promise<{ tabId: string; title?: string | null }> @@ -743,7 +745,11 @@ type RuntimeNotifier = { splitTerminal( tabId: string, paneRuntimeId: number, - opts: { direction: 'horizontal' | 'vertical'; command?: string } + opts: { + direction: 'horizontal' | 'vertical' + command?: string + telemetrySource?: TerminalPaneSplitSource + } ): void renameTerminal(tabId: string, title: string | null): void focusTerminal(tabId: string, worktreeId: string, leafId?: string | null): void @@ -10112,12 +10118,13 @@ export class OrcaRuntimeService { async splitTerminal( handle: string, - opts: { - direction?: 'horizontal' | 'vertical' - command?: string - env?: Record - activate?: boolean - } = {} + opts: { + direction?: 'horizontal' | 'vertical' + command?: string + env?: Record + activate?: boolean + telemetrySource?: TerminalPaneSplitSource + } = {} ): Promise { const livePty = this.getLivePtyForHandle(handle) if (livePty) { @@ -10136,10 +10143,11 @@ export class OrcaRuntimeService { } } - this.notifier?.splitTerminal(leaf.tabId, leaf.paneRuntimeId, { - direction, - command: opts.command - }) + this.notifier?.splitTerminal(leaf.tabId, leaf.paneRuntimeId, { + direction, + command: opts.command, + telemetrySource: opts.telemetrySource + }) const newHandle = await this.waitForNewLeafInTab(leaf.tabId, leafKeysBefore) return { handle: newHandle, tabId: leaf.tabId, paneRuntimeId: leaf.paneRuntimeId } @@ -10147,12 +10155,13 @@ export class OrcaRuntimeService { private async splitPtyBackedTerminal( pty: RuntimePtyWorktreeRecord, - opts: { - direction?: 'horizontal' | 'vertical' - command?: string - env?: Record - activate?: boolean - } = {} + opts: { + direction?: 'horizontal' | 'vertical' + command?: string + env?: Record + activate?: boolean + telemetrySource?: TerminalPaneSplitSource + } = {} ): Promise { if (!this.ptyController?.spawn) { throw new Error('runtime_unavailable') @@ -10200,10 +10209,11 @@ export class OrcaRuntimeService { title: null, activate: opts.activate !== false, tabId: parentTabId, - leafId, - splitFromLeafId: parsedPaneKey.leafId, - splitDirection: direction - }) + leafId, + splitFromLeafId: parsedPaneKey.leafId, + splitDirection: direction, + splitTelemetrySource: opts.telemetrySource + }) } catch (error) { this.ptyController.kill?.(result.id) throw error diff --git a/src/main/runtime/rpc/methods/terminal.ts b/src/main/runtime/rpc/methods/terminal.ts index e7a2e5412..3440f1763 100644 --- a/src/main/runtime/rpc/methods/terminal.ts +++ b/src/main/runtime/rpc/methods/terminal.ts @@ -12,6 +12,7 @@ import { encodeTerminalStreamText, type TerminalStreamFrame } from '../../../../shared/terminal-stream-protocol' +import { TERMINAL_PANE_SPLIT_SOURCES } from '../../../../shared/feature-education-telemetry' // Why: when a mobile client subscribes the server resizes the PTY to phone // dims and serializes the buffer. Sending only the visible screen meant @@ -352,7 +353,8 @@ const TerminalSplit = TerminalHandle.extend({ .pipe(z.union([z.enum(['vertical', 'horizontal']), z.undefined()])) .optional(), command: OptionalString, - env: z.record(z.string(), z.string()).optional() + env: z.record(z.string(), z.string()).optional(), + telemetrySource: z.enum(TERMINAL_PANE_SPLIT_SOURCES).optional() }) const TerminalStop = z.object({ @@ -593,7 +595,8 @@ export const TERMINAL_METHODS: RpcAnyMethod[] = [ split: await runtime.splitTerminal(params.terminal, { direction: params.direction, command: params.command, - env: params.env + env: params.env, + telemetrySource: params.telemetrySource }) }) }), diff --git a/src/main/runtime/rpc/schemas.test.ts b/src/main/runtime/rpc/schemas.test.ts index af96f006e..4d9cc3609 100644 --- a/src/main/runtime/rpc/schemas.test.ts +++ b/src/main/runtime/rpc/schemas.test.ts @@ -26,6 +26,11 @@ function expectParses(schema: ZodType, value: unknown): void { ) } +function expectRejects(schema: ZodType, value: unknown): void { + const result = schema.safeParse(value) + expect(result.success).toBe(false) +} + function methodParams( methods: readonly { name: string; params: ZodType | null }[], name: string @@ -62,6 +67,14 @@ describe('RPC optional pipe schemas', () => { it('accepts omitted terminal and worktree optional fields while required fields are present', () => { expectParses(methodParams(TERMINAL_METHODS, 'terminal.split'), { terminal: 'terminal-1' }) + expectParses(methodParams(TERMINAL_METHODS, 'terminal.split'), { + terminal: 'terminal-1', + telemetrySource: 'contextual_tour' + }) + expectRejects(methodParams(TERMINAL_METHODS, 'terminal.split'), { + terminal: 'terminal-1', + telemetrySource: 'raw-source' + }) expectParses(methodParams(WORKTREE_METHODS, 'worktree.create'), { repo: 'repo-1' }) expectParses(methodParams(WORKTREE_METHODS, 'worktree.prefetchCreateBase'), { repo: 'repo-1' }) }) diff --git a/src/main/window/attach-main-window-services.ts b/src/main/window/attach-main-window-services.ts index 7cef390b9..72e109992 100644 --- a/src/main/window/attach-main-window-services.ts +++ b/src/main/window/attach-main-window-services.ts @@ -336,7 +336,10 @@ function registerRuntimeWindowLifecycle( ...(opts.tabId !== undefined ? { tabId: opts.tabId } : {}), ...(opts.leafId !== undefined ? { leafId: opts.leafId } : {}), ...(opts.splitFromLeafId !== undefined ? { splitFromLeafId: opts.splitFromLeafId } : {}), - ...(opts.splitDirection !== undefined ? { splitDirection: opts.splitDirection } : {}) + ...(opts.splitDirection !== undefined ? { splitDirection: opts.splitDirection } : {}), + ...(opts.splitTelemetrySource !== undefined + ? { splitTelemetrySource: opts.splitTelemetrySource } + : {}) }) }), splitTerminal: (tabId, paneRuntimeId, opts) => { @@ -344,7 +347,8 @@ function registerRuntimeWindowLifecycle( tabId, paneRuntimeId, direction: opts.direction, - command: opts.command + command: opts.command, + telemetrySource: opts.telemetrySource }) }, renameTerminal: (tabId, title) => send('ui:renameTerminal', { tabId, title }), diff --git a/src/preload/api-types.ts b/src/preload/api-types.ts index 30ec3c085..37cc345a4 100644 --- a/src/preload/api-types.ts +++ b/src/preload/api-types.ts @@ -9,6 +9,7 @@ import type { } from '../shared/hosted-review' import type { NativeFileDropPayload } from '../shared/native-file-drop' import type { AppIdentity } from '../shared/app-identity' +import type { TerminalPaneSplitSource } from '../shared/feature-education-telemetry' import type { BaseRefDefaultResult, BaseRefSearchResult, @@ -2066,6 +2067,7 @@ export type PreloadApi = { leafId?: string splitFromLeafId?: string splitDirection?: 'horizontal' | 'vertical' + splitTelemetrySource?: TerminalPaneSplitSource }) => void ) => () => void onRequestTerminalCreate: ( @@ -2091,6 +2093,7 @@ export type PreloadApi = { paneRuntimeId: number direction: 'horizontal' | 'vertical' command?: string + telemetrySource?: TerminalPaneSplitSource }) => void ) => () => void onRenameTerminal: ( diff --git a/src/preload/index.ts b/src/preload/index.ts index 5db787809..a83f03fd3 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -8,6 +8,7 @@ import { glApi } from './gitlab' import type { AppIdentity } from '../shared/app-identity' import type { CliInstallStatus } from '../shared/cli-install-types' import type { AgentHookInstallStatus } from '../shared/agent-hook-types' +import type { TerminalPaneSplitSource } from '../shared/feature-education-telemetry' import type { BaseRefSearchResult, BaseRefDefaultResult, @@ -2689,6 +2690,7 @@ const api = { leafId?: string splitFromLeafId?: string splitDirection?: 'horizontal' | 'vertical' + splitTelemetrySource?: TerminalPaneSplitSource }) => void ): (() => void) => { const listener = ( @@ -2704,6 +2706,7 @@ const api = { leafId?: string splitFromLeafId?: string splitDirection?: 'horizontal' | 'vertical' + splitTelemetrySource?: TerminalPaneSplitSource } ) => callback(data) ipcRenderer.on('ui:createTerminal', listener) @@ -2749,6 +2752,7 @@ const api = { paneRuntimeId: number direction: 'horizontal' | 'vertical' command?: string + telemetrySource?: TerminalPaneSplitSource }) => void ): (() => void) => { const listener = ( @@ -2758,6 +2762,7 @@ const api = { paneRuntimeId: number direction: 'horizontal' | 'vertical' command?: string + telemetrySource?: TerminalPaneSplitSource } ) => callback(data) ipcRenderer.on('ui:splitTerminal', listener) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 8c194053b..f5ed6f79c 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -118,6 +118,7 @@ import type { RemoteWorkspacePatchResult } from '../../shared/remote-workspace-t import type { OnboardingState } from '../../shared/types' import { FLOATING_TERMINAL_WORKTREE_ID } from '../../shared/constants' import { ContextualTourOverlay } from './components/contextual-tours/ContextualTourOverlay' +import { SetupGuideTelemetryObserver } from './components/setup-guide/SetupGuideTelemetryObserver' import { getFeatureTipsAppOpenDecision, isCliFeatureTipCompleted @@ -1936,6 +1937,7 @@ function App(): React.JSX.Element { ) : null} + {persistedUIReady ? : null} {/* Why: mount PetOverlay only after persisted UI hydration, with both independent pet toggles allowing it; otherwise a hidden pet diff --git a/src/renderer/src/assets/main.css b/src/renderer/src/assets/main.css index 25c740adb..3b2440a94 100644 --- a/src/renderer/src/assets/main.css +++ b/src/renderer/src/assets/main.css @@ -2928,3 +2928,28 @@ html.onboarding-tour-start-transition::view-transition-new(root) { inset 0 1px 0 0 color-mix(in srgb, var(--foreground) 5%, transparent), 0 10px 24px rgba(0, 0, 0, 0.18); } + +/* Why: a tour panel must read as elevated above the chrome it is teaching about + without resorting to color. A 1px inner top highlight plus the documented + floating shadow keeps it above the surface in both light and dark modes. */ +.orca-contextual-tour-panel { + background: linear-gradient( + 180deg, + color-mix(in srgb, var(--foreground) 4%, var(--popover)) 0%, + var(--popover) 12% + ); + box-shadow: + inset 0 1px 0 0 color-mix(in srgb, var(--foreground) 10%, transparent), + 0 10px 24px rgba(0, 0, 0, 0.18); +} + +.dark .orca-contextual-tour-panel { + background: linear-gradient( + 180deg, + color-mix(in srgb, var(--foreground) 4%, var(--popover)) 0%, + var(--popover) 14% + ); + box-shadow: + inset 0 1px 0 0 color-mix(in srgb, var(--foreground) 5%, transparent), + 0 10px 24px rgba(0, 0, 0, 0.18); +} diff --git a/src/renderer/src/components/contextual-tours/ContextualTourOverlay.tsx b/src/renderer/src/components/contextual-tours/ContextualTourOverlay.tsx index eeba04e1c..294e1f3f0 100644 --- a/src/renderer/src/components/contextual-tours/ContextualTourOverlay.tsx +++ b/src/renderer/src/components/contextual-tours/ContextualTourOverlay.tsx @@ -69,6 +69,8 @@ export function ContextualTourOverlay(): JSX.Element | null { const telemetryOutcomeSentRef = useRef(false) const telemetryStepsSeenRef = useRef>(new Set()) const telemetryTotalStepsRef = useRef(1) + const telemetryFurthestStepIndexRef = useRef(0) + const telemetryDefinedStepCountRef = useRef(1) const activeTour = useMemo( () => (activeTourId ? getContextualTour(activeTourId) : null), @@ -85,12 +87,19 @@ export function ContextualTourOverlay(): JSX.Element | null { return } telemetryOutcomeSentRef.current = true + const furthestStepIndex = telemetryFurthestStepIndexRef.current trackContextualTourOutcome({ tourId: activeTourId, source: activeTourSource, outcome, stepsSeen: telemetryStepsSeenRef.current.size, - totalSteps: telemetryTotalStepsRef.current + totalSteps: telemetryTotalStepsRef.current, + ...(furthestStepIndex > 0 + ? { + furthestStepIndex, + definedStepCount: telemetryDefinedStepCountRef.current + } + : {}) }) }, [activeTourId, activeTourSource] @@ -108,8 +117,10 @@ export function ContextualTourOverlay(): JSX.Element | null { telemetryOutcomeSentRef.current = false telemetryStepsSeenRef.current = new Set() telemetryTotalStepsRef.current = 1 + telemetryFurthestStepIndexRef.current = 0 + telemetryDefinedStepCountRef.current = activeTour?.steps.length ?? 1 setRenderState(null) - }, [activeTourId]) + }, [activeTour?.steps.length, activeTourId]) useEffect(() => { if (!activeTour || !activeTourId) { @@ -159,6 +170,7 @@ export function ContextualTourOverlay(): JSX.Element | null { const targetExists = (selector: string): boolean => getMeasurableContextualTourTarget(selector) !== null const visibleStepIndexes = getVisibleContextualTourStepIndexes(activeTour, targetExists) + telemetryDefinedStepCountRef.current = activeTour.steps.length telemetryTotalStepsRef.current = Math.max( telemetryTotalStepsRef.current, getContextualTourOutcomeStepTotal(visibleStepIndexes) @@ -239,6 +251,10 @@ export function ContextualTourOverlay(): JSX.Element | null { } telemetryTourIdRef.current = activeTourId telemetryStepsSeenRef.current.add(activeStepIndex) + telemetryFurthestStepIndexRef.current = Math.max( + telemetryFurthestStepIndexRef.current, + activeStepIndex + 1 + ) trackContextualTourShown({ tourId: activeTourId, source: activeTourSource, @@ -251,6 +267,10 @@ export function ContextualTourOverlay(): JSX.Element | null { return } telemetryStepsSeenRef.current.add(activeStepIndex) + telemetryFurthestStepIndexRef.current = Math.max( + telemetryFurthestStepIndexRef.current, + activeStepIndex + 1 + ) }, [activeStepIndex, activeTourId, renderState]) useEffect(() => { diff --git a/src/renderer/src/components/contextual-tours/contextual-tour-step-actions.ts b/src/renderer/src/components/contextual-tours/contextual-tour-step-actions.ts index 04a705cc1..c68a797b8 100644 --- a/src/renderer/src/components/contextual-tours/contextual-tour-step-actions.ts +++ b/src/renderer/src/components/contextual-tours/contextual-tour-step-actions.ts @@ -10,7 +10,7 @@ export function performContextualTourStepAction(args: { detachContextualTourSource: () => void setSidebarOpen: (open: boolean) => void openTaskPage: () => void - openModal: (modal: 'setup-guide') => void + openModal: (modal: 'setup-guide', data?: Record) => void canCreateWorkspace: boolean openWorkspaceComposer: () => void dispatchTerminalPaneSplit: (detail: RequestActiveTerminalPaneSplitDetail) => void @@ -60,7 +60,7 @@ export function performContextualTourStepAction(args: { case 'open-getting-started': args.finishTour() args.schedule(() => { - args.openModal('setup-guide') + args.openModal('setup-guide', { telemetrySource: 'contextual_tour' }) }) } } diff --git a/src/renderer/src/components/settings/SettingsSetupGuideCard.tsx b/src/renderer/src/components/settings/SettingsSetupGuideCard.tsx index e0d8b7fdb..315585f8d 100644 --- a/src/renderer/src/components/settings/SettingsSetupGuideCard.tsx +++ b/src/renderer/src/components/settings/SettingsSetupGuideCard.tsx @@ -76,7 +76,12 @@ export function SettingsSetupGuideCard(): React.JSX.Element | null { type="button" size="sm" className="w-fit shrink-0 whitespace-nowrap gap-1.5" - onClick={() => openModal('setup-guide', { setupStepId: firstUnfinishedStepId })} + onClick={() => + openModal('setup-guide', { + setupStepId: firstUnfinishedStepId, + telemetrySource: 'settings' + }) + } > {setupComplete ? 'Review setup' : 'Continue setup'} diff --git a/src/renderer/src/components/setup-guide/SetupGuideModal.tsx b/src/renderer/src/components/setup-guide/SetupGuideModal.tsx index 511581f41..ec1708acc 100644 --- a/src/renderer/src/components/setup-guide/SetupGuideModal.tsx +++ b/src/renderer/src/components/setup-guide/SetupGuideModal.tsx @@ -15,6 +15,7 @@ import { import { useAppStore } from '@/store' import { FeatureWallSetupChecklist } from '../feature-wall/FeatureWallSetupChecklist' import { useSetupGuideProgress } from './use-setup-guide-progress' +import { useSetupGuideOpenCloseTelemetry } from './use-setup-guide-telemetry' export default function SetupGuideModal(): JSX.Element | null { const activeModal = useAppStore((s) => s.activeModal) @@ -36,8 +37,21 @@ export default function SetupGuideModal(): JSX.Element | null { const requestedStepId = isFeatureWallSetupStepId(modalData.setupStepId) ? modalData.setupStepId : null + const telemetrySource = + typeof modalData.setupGuideSource === 'string' + ? modalData.setupGuideSource + : typeof modalData.telemetrySource === 'string' + ? modalData.telemetrySource + : 'unknown' const activeStep = setupSteps.find((step) => step.id === activeStepId) ?? setupSteps[0] ?? null + useSetupGuideOpenCloseTelemetry({ + isOpen, + source: telemetrySource, + progress, + activeStepId: activeStep?.id ?? null + }) + useEffect(() => { if (!isOpen) { setUserSelectedStep(false) diff --git a/src/renderer/src/components/setup-guide/SetupGuideTelemetryObserver.tsx b/src/renderer/src/components/setup-guide/SetupGuideTelemetryObserver.tsx new file mode 100644 index 000000000..ae1f9fd3e --- /dev/null +++ b/src/renderer/src/components/setup-guide/SetupGuideTelemetryObserver.tsx @@ -0,0 +1,15 @@ +import { useAppStore } from '@/store' +import { useSetupGuideProgress } from './use-setup-guide-progress' +import { useSetupGuideStepCompletionTelemetry } from './use-setup-guide-telemetry' + +export function SetupGuideTelemetryObserver(): null { + const setupGuideVisible = useAppStore((s) => s.activeModal === 'setup-guide') + const progress = useSetupGuideProgress(true, false, false) + + useSetupGuideStepCompletionTelemetry({ + progress, + setupGuideVisible + }) + + return null +} diff --git a/src/renderer/src/components/setup-guide/use-setup-guide-telemetry.test.ts b/src/renderer/src/components/setup-guide/use-setup-guide-telemetry.test.ts new file mode 100644 index 000000000..9317ab699 --- /dev/null +++ b/src/renderer/src/components/setup-guide/use-setup-guide-telemetry.test.ts @@ -0,0 +1,117 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { FeatureWallSetupProgress } from '../feature-wall/feature-wall-setup-progress' +import { + FEATURE_WALL_SETUP_STEP_IDS, + type FeatureWallSetupStepId +} from '../../../../shared/feature-wall-setup-steps' +import { readEmittedSetupGuideStepIds } from '@/lib/feature-education-telemetry' +import { + createSetupGuideStepCompletionTelemetryState, + recordSetupGuideStepCompletionTelemetry +} from './use-setup-guide-telemetry' + +const consoleInfoMock = vi.hoisted(() => vi.fn()) +const trackMock = vi.hoisted(() => vi.fn()) + +vi.mock('@/lib/telemetry', () => ({ + track: trackMock +})) + +afterEach(() => { + consoleInfoMock.mockClear() + trackMock.mockClear() + vi.restoreAllMocks() + vi.unstubAllGlobals() +}) + +describe('setup guide step completion telemetry', () => { + beforeEach(() => { + vi.spyOn(console, 'info').mockImplementation(consoleInfoMock) + }) + + it('seeds startup-hydrated completed steps without backfilling completion events', () => { + vi.stubGlobal('localStorage', createMemoryStorage()) + const state = createSetupGuideStepCompletionTelemetryState() + + recordSetupGuideStepCompletionTelemetry({ + state, + progress: createProgress({}), + setupGuideVisible: false + }) + recordSetupGuideStepCompletionTelemetry({ + state, + progress: createProgress({ 'split-terminal': true }), + setupGuideVisible: false + }) + + expect(trackMock).not.toHaveBeenCalled() + expect([...readEmittedSetupGuideStepIds()]).toEqual(['split-terminal']) + + recordSetupGuideStepCompletionTelemetry({ + state, + progress: createProgress({ 'split-terminal': true, 'two-worktrees': true }), + setupGuideVisible: false + }) + + expect(trackMock).not.toHaveBeenCalled() + expect([...readEmittedSetupGuideStepIds()].sort()).toEqual(['split-terminal', 'two-worktrees']) + }) + + it('emits visible setup-guide completions during the startup baseline window', () => { + vi.stubGlobal('localStorage', createMemoryStorage()) + const state = createSetupGuideStepCompletionTelemetryState() + + recordSetupGuideStepCompletionTelemetry({ + state, + progress: createProgress({}), + setupGuideVisible: true + }) + recordSetupGuideStepCompletionTelemetry({ + state, + progress: createProgress({ notifications: true }), + setupGuideVisible: true + }) + + expect(consoleInfoMock).toHaveBeenCalledWith( + '[feature-education-telemetry:test-mode]', + 'setup_guide_step_completed', + { + step_id: 'notifications', + section_id: 'setup', + completed_count: 1, + total_steps: 8, + setup_guide_visible: true + } + ) + expect(trackMock).not.toHaveBeenCalled() + }) +}) + +function createProgress( + doneOverrides: Partial> +): FeatureWallSetupProgress { + const stepDone = Object.fromEntries( + FEATURE_WALL_SETUP_STEP_IDS.map((stepId) => [stepId, doneOverrides[stepId] === true]) + ) as Record + return { + stepDone, + coreDoneCount: FEATURE_WALL_SETUP_STEP_IDS.filter((stepId) => stepDone[stepId]).length, + coreTotal: FEATURE_WALL_SETUP_STEP_IDS.length + } +} + +function createMemoryStorage(): Storage { + const values = new Map() + return { + get length() { + return values.size + }, + clear: () => values.clear(), + getItem: (key) => values.get(key) ?? null, + key: (index) => [...values.keys()][index] ?? null, + removeItem: (key) => values.delete(key), + setItem: (key, value) => { + values.set(key, value) + } + } +} diff --git a/src/renderer/src/components/setup-guide/use-setup-guide-telemetry.ts b/src/renderer/src/components/setup-guide/use-setup-guide-telemetry.ts new file mode 100644 index 000000000..1fb4382cb --- /dev/null +++ b/src/renderer/src/components/setup-guide/use-setup-guide-telemetry.ts @@ -0,0 +1,178 @@ +import { useCallback, useEffect, useMemo, useRef } from 'react' +import { + FEATURE_WALL_SETUP_STEP_IDS, + getFeatureWallSetupSteps, + type FeatureWallSetupStepId +} from '../../../../shared/feature-wall-setup-steps' +import type { SetupGuideSource } from '../../../../shared/feature-education-telemetry' +import type { FeatureWallSetupProgress } from '../feature-wall/feature-wall-setup-progress' +import { + persistEmittedSetupGuideStepId, + readEmittedSetupGuideStepIds, + trackSetupGuideClosed, + trackSetupGuideOpened, + trackSetupGuideStepCompleted +} from '@/lib/feature-education-telemetry' + +type SetupGuideTelemetrySession = { + source: SetupGuideSource + initialCompletedCount: number +} + +type SetupGuideTelemetrySnapshot = { + completedCount: number + totalSteps: number + activeStepId: FeatureWallSetupStepId | 'none' +} + +type SetupGuideStepCompletionTelemetryState = { + previousDone: Record | null + emitted: Set | null +} + +export function useSetupGuideOpenCloseTelemetry(args: { + isOpen: boolean + source: string | null | undefined + progress: FeatureWallSetupProgress + activeStepId: FeatureWallSetupStepId | null +}): void { + const setupSteps = useMemo(() => getFeatureWallSetupSteps(), []) + const sessionRef = useRef(null) + const snapshotRef = useRef({ + completedCount: 0, + totalSteps: FEATURE_WALL_SETUP_STEP_IDS.length, + activeStepId: 'none' + }) + + const completedCount = countCompletedSetupSteps(args.progress.stepDone) + const firstIncompleteStepId = + setupSteps.find((step) => !args.progress.stepDone[step.id])?.id ?? 'none' + + snapshotRef.current = { + completedCount, + totalSteps: setupSteps.length, + activeStepId: args.activeStepId ?? 'none' + } + + const closeSession = useCallback((outcome: 'completed' | 'dismissed' | 'interrupted'): void => { + const session = sessionRef.current + if (!session) { + return + } + sessionRef.current = null + const snapshot = snapshotRef.current + trackSetupGuideClosed({ + source: session.source, + outcome: snapshot.completedCount >= snapshot.totalSteps ? 'completed' : outcome, + initialCompletedCount: session.initialCompletedCount, + finalCompletedCount: snapshot.completedCount, + totalSteps: snapshot.totalSteps, + activeStepId: snapshot.activeStepId + }) + }, []) + + useEffect(() => { + if (args.isOpen && !sessionRef.current) { + const source = trackSetupGuideOpened({ + source: args.source, + initialCompletedCount: completedCount, + totalSteps: setupSteps.length, + firstIncompleteStepId + }) + sessionRef.current = { source, initialCompletedCount: completedCount } + return + } + if (!args.isOpen && sessionRef.current) { + closeSession('dismissed') + } + }, [ + args.isOpen, + args.source, + closeSession, + completedCount, + firstIncompleteStepId, + setupSteps.length + ]) + + useEffect(() => { + return () => { + closeSession('interrupted') + } + }, [closeSession]) +} + +export function useSetupGuideStepCompletionTelemetry(args: { + progress: FeatureWallSetupProgress + setupGuideVisible: boolean +}): void { + const stateRef = useRef(null) + if (!stateRef.current) { + stateRef.current = createSetupGuideStepCompletionTelemetryState() + } + + useEffect(() => { + recordSetupGuideStepCompletionTelemetry({ + state: stateRef.current!, + progress: args.progress, + setupGuideVisible: args.setupGuideVisible + }) + }, [args.progress, args.progress.stepDone, args.setupGuideVisible]) +} + +export function createSetupGuideStepCompletionTelemetryState(): SetupGuideStepCompletionTelemetryState { + return { + previousDone: null, + emitted: null + } +} + +export function recordSetupGuideStepCompletionTelemetry(args: { + state: SetupGuideStepCompletionTelemetryState + progress: FeatureWallSetupProgress + setupGuideVisible: boolean +}): void { + if (!args.state.emitted) { + args.state.emitted = readEmittedSetupGuideStepIds() + } + const previousDone = args.state.previousDone + args.state.previousDone = { ...args.progress.stepDone } + const emitted = args.state.emitted + if (!previousDone || !args.setupGuideVisible) { + // Why: hidden async refresh can flip already-complete setup state from false + // to true; only visible guide actions are attributable enough to event. + persistCompletedSetupGuideStepBaselines(args.progress.stepDone, emitted) + return + } + + const completedCount = countCompletedSetupSteps(args.progress.stepDone) + for (const stepId of FEATURE_WALL_SETUP_STEP_IDS) { + if (!args.progress.stepDone[stepId] || previousDone[stepId] || emitted.has(stepId)) { + continue + } + emitted.add(stepId) + persistEmittedSetupGuideStepId(stepId) + trackSetupGuideStepCompleted({ + stepId, + completedCount, + totalSteps: FEATURE_WALL_SETUP_STEP_IDS.length, + setupGuideVisible: args.setupGuideVisible + }) + } +} + +function countCompletedSetupSteps(done: Record): number { + return FEATURE_WALL_SETUP_STEP_IDS.filter((stepId) => done[stepId]).length +} + +function persistCompletedSetupGuideStepBaselines( + done: Record, + emitted: Set +): void { + for (const stepId of FEATURE_WALL_SETUP_STEP_IDS) { + if (!done[stepId] || emitted.has(stepId)) { + continue + } + emitted.add(stepId) + persistEmittedSetupGuideStepId(stepId) + } +} diff --git a/src/renderer/src/components/sidebar/SetupGuideSidebarEntry.tsx b/src/renderer/src/components/sidebar/SetupGuideSidebarEntry.tsx index 31537d636..b93247674 100644 --- a/src/renderer/src/components/sidebar/SetupGuideSidebarEntry.tsx +++ b/src/renderer/src/components/sidebar/SetupGuideSidebarEntry.tsx @@ -53,7 +53,12 @@ export function SetupGuideSidebarEntry(): React.JSX.Element | null { >