Skip to content

feat(agents): instrument /code/agents page with analytics events#2747

Merged
andrewm4894 merged 3 commits into
mainfrom
agents-page-analytics
Jun 18, 2026
Merged

feat(agents): instrument /code/agents page with analytics events#2747
andrewm4894 merged 3 commits into
mainfrom
agents-page-analytics

Conversation

@andrewm4894

Copy link
Copy Markdown
Member

What

Adds product analytics to the /code/agents configuration page, mirroring the inbox-reports instrumentation pattern (INBOX_VIEWED / INBOX_REPORT_ACTION).

Two events:

  • Agents viewed — fires once per visit via a new useTrackAgentsViewed hook (modeled on useTrackInboxViewed), after responder/integration/autonomy data settles. Captures GitHub-integration state, responder total/enabled counts, the user's auto-start priority threshold, and whether the setup-task entry point is shown.
  • Agents action — covers three interactions from ConfigureAgentsSection:
    • change_autostart_priority (with new threshold)
    • open_mcp_servers
    • run_setup_agent (with success)

Files

  • packages/shared/src/analytics-events.tsAGENTS_VIEWED / AGENTS_ACTION event names, property interfaces, and EventPropertyMap entries
  • packages/ui/src/features/agents/hooks/useTrackAgentsViewed.ts — new view-tracking hook
  • packages/ui/src/features/inbox/components/ConfigureAgentsSection.tsx — mounts the hook and fires AGENTS_ACTION

Notes

This complements the already-shipped scout instrumentation (Scout fleet viewed, Scout action, etc.). Once merged and shipped, these events will flow into project 2 alongside the scout events.

Testing

  • pnpm typecheck passes (run by pre-commit hook)
  • Biome clean

Add AGENTS_VIEWED and AGENTS_ACTION events mirroring the inbox-reports
instrumentation. AGENTS_VIEWED fires once per visit via a new
useTrackAgentsViewed hook; AGENTS_ACTION covers change_autostart_priority,
open_mcp_servers, and run_setup_agent from ConfigureAgentsSection.
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 45d82bd.

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
packages/ui/src/features/agents/hooks/useTrackAgentsViewed.ts:34-37
**`isLoading` guard fires on error, locking in bad analytics data**

When any of the three backing fetches fail (network error, 4xx, etc.), the react-query `isPending`/`isLoading` flag drops to `false` even though data was never successfully fetched. This hook then fires immediately with whatever default/stale values are present — e.g. `has_github_integration: false` even when the user does have GitHub connected — and `firedRef.current` becomes `true`, so the event can never re-fire for the rest of that component lifetime.

`useTrackInboxViewed` (which this is modeled on) explicitly chose `!isSuccess` over `!isLoading` with a comment explaining exactly this failure mode. The input contract here would need a corresponding `isSuccess: boolean` (or `isError: boolean`) field passed from the caller alongside the combined loading flag, similar to how react-query's `isSuccess` is threaded through in the inbox hook.

### Issue 2 of 2
packages/ui/src/features/inbox/components/ConfigureAgentsSection.tsx:355-362
**`run_setup_agent` tracked twice when `result.success` is `true`**

The `track(AGENTS_ACTION, { action_type: "run_setup_agent", success: result.success })` call at line 358 fires unconditionally on every non-throwing `createTask` response, including the success path. The immediately-following `if (result.success)` block then also fires `TASK_CREATED`. This is fine, but note that because both the `try` path (line 358) and the `catch` path (line 384) call the same `run_setup_agent` event, a throw will produce exactly one event — but a `result.success === false` (non-throwing failure from `createTask`) will also produce exactly one event. The duplication risk is only if someone later wraps the `TASK_CREATED` call and assumes `AGENTS_ACTION` already fired; the current code is correct, but it may be cleaner to guard the line-358 call with `if (!result.success)` so the catch block's event stays as the sole failure-path emitter and the success path is covered by the existing `TASK_CREATED` event already fired.

Reviews (1): Last reviewed commit: "feat(agents): instrument /code/agents pa..." | Re-trigger Greptile

Comment thread packages/ui/src/features/agents/hooks/useTrackAgentsViewed.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd3864f097

ℹ️ 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".

Comment thread packages/ui/src/features/agents/hooks/useTrackAgentsViewed.ts Outdated
Addresses review: an errored integrations fetch also clears isLoading, so
the previous gate could fire AGENTS_VIEWED with default values (e.g.
has_github_integration: false) and lock firedRef, preventing a correct
re-fire after refetch. Add an isError gate (sourced from the integrations
query) mirroring the !isSuccess gate in useTrackInboxViewed.
@andrewm4894 andrewm4894 self-assigned this Jun 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f11b0d782

ℹ️ 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".

Comment thread packages/ui/src/features/inbox/components/ConfigureAgentsSection.tsx Outdated
Comment thread packages/ui/src/features/inbox/components/ConfigureAgentsSection.tsx Outdated
Addresses Codex review on the analytics PR:
- has_github_integration: derive from the integrations query data instead of
  the store-backed value, which is hydrated by a passive effect that lags the
  query by a render and could lock in a stale false on the settle render.
- responder counts: count only RESPONDER_AGENT_GROUPS sources; displayValues
  also carries the legacy signals_scout toggle, which renders separately and
  was inflating responder_total_count / responder_enabled_count.
- run_setup_agent: emit success:false at the precondition guards (missing
  github/repo/region/user-integration, unresolved model) so failed setup
  attempts stay in the funnel instead of biasing the success rate upward.
@andrewm4894 andrewm4894 added the Stamphog This will request an autostamp by stamphog on small changes label Jun 18, 2026
@andrewm4894 andrewm4894 enabled auto-merge (squash) June 18, 2026 09:31

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pure analytics instrumentation — new event types, a once-per-visit view hook with proper error/loading guards, and action tracking calls. All inline review concerns were addressed in follow-up commits that are present in the current diff; no unresolved substantive issues remain.

@andrewm4894 andrewm4894 merged commit 7b0c7c3 into main Jun 18, 2026
26 checks passed
@andrewm4894 andrewm4894 deleted the agents-page-analytics branch June 18, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant