Files
PaperClipAI/ui
Dotta d128e2db6f feat(analytics): track onboarding step failures and agent chat sends (#22814)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - On Paperclip Cloud, browser analytics tracks onboarding wizard steps
through PostHog
> - Today, failures on the model connection step and user replies in the
onboarding chat emit no browser analytics events
> - Without those events, teams cannot tell whether users hit an error
during model setup or leave after the automatic welcome greeting
> - This pull request adds structured enum-only browser events for
onboarding step failures and agent chat message sends
> - The benefit is clear visibility into onboarding drop-offs and
post-launch engagement without sending customer text or raw error
strings

## Linked Issues or Issue Description

**What existing behavior does this improve?**
Cloud browser onboarding analytics in
`ui/src/lib/analytics/onboarding-analytics.ts`,
`ui/src/components/OnboardingWizard.tsx`, `ui/src/pages/AgentChat.tsx`,
and `ui/src/pages/IssueDetail.tsx`.

**Subsystem affected**
ui/ — React + Vite board UI

**Current behavior**
The onboarding wizard emits `onboarding_opened`,
`onboarding_step_viewed`, `onboarding_step_completed`, and
`onboarding_dismissed`. Failures during API key storage, subscription
sign-in, adapter environment tests, agent creation, and onboarding
welcome greeting emit no failure event. Onboarding also launches into
Agent Chat (where server-side `task.created` skips conversations), so
user replies after launch emit no distinct engagement event.

**Proposed behavior**
Add two browser analytics events on Cloud (inert on self-hosted installs
and gated on existing analytics consent):
- `onboarding_step_failed` with bounded `step`, `reason`, sanitized
`provider`, and `method` fields.
- `agent_chat_message_sent` with `surface` (`onboarding_chat` or
`agent_chat`).

**Reason and benefit**
Teams can separate actual setup errors (bad API key, failed OAuth,
failed environment test, failed greeting) from user abandonment on the
model-connect step, and separate passive greeting-only visits from
active replies in Agent Chat.

**Breaking changes**
None. Existing event names and properties are unchanged, and no
`PAPERCLIP_EVENTS` server event names are captured from the browser.

## What Changed

- Add `onboarding_step_failed` (`captureOnboardingStepFailed`) and
`agent_chat_message_sent` (`captureAgentChatMessageSent`) to
`ui/src/lib/analytics/onboarding-analytics.ts`, with bounded reason
enums and provider slug validation.
- Wire `captureOnboardingStepFailed` into the failure paths in
`ui/src/components/OnboardingWizard.tsx` (API key save, subscription
sign-in failure, environment test failure, agent creation failure, chat
launch failure) and `ui/src/pages/AgentChat.tsx` (onboarding greeting
failure).
- Wire `captureAgentChatMessageSent` in `ui/src/pages/IssueDetail.tsx`
when a user posts a comment to an Agent Chat conversation.
- Add unit tests in `ui/src/lib/analytics/onboarding-analytics.test.tsx`
covering failure capture, unsafe provider filtering, and chat surface
tagging.

## Verification

- `pnpm --filter @paperclipai/ui typecheck` — passed after rebase onto
`origin/master`.
- `pnpm --filter @paperclipai/ui exec vitest run
src/lib/analytics/onboarding-analytics.test.tsx
src/lib/analytics/product-analytics-events.test.ts
src/lib/analytics/product-analytics.test.ts` — 3 test files, 28/28 tests
passed (including the event-ownership test proving no `PAPERCLIP_EVENTS`
are captured from UI code).
- Prior to rebase, ran the full `ui/src/lib/analytics/` directory — 7
test files, 255/255 tests passed.

## Risks

- Low risk. Browser product analytics stays completely inert on
self-hosted installs and respects Cloud consent gates. No message
content, raw error text, credentials, or PII leave the browser.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Google Gemini (high reasoning mode) in Antigravity, with file editing,
git, and shell tool use.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-24 14:24:37 -06:00
..
…

@paperclipai/ui

Published static assets for the Paperclip board UI.

What gets published

The npm package contains the production build under dist/. It does not ship the UI source tree or workspace-only dependencies.

Storybook

Storybook config, stories, and fixtures live under ui/storybook/.

pnpm --filter @paperclipai/ui storybook
pnpm --filter @paperclipai/ui build-storybook

Typical use

Install the package, then serve or copy the built files from node_modules/@paperclipai/ui/dist.

Editor dependency identity

Keep the root and workspace overrides for @codemirror/state, @codemirror/view, and @lezer/common aligned. CodeMirror requires shared extension identity, while Lezer parsers and syntax highlighters require shared NodeProp IDs. Multiple Lezer copies can crash code-block highlighting with tags is not iterable. src/lib/codemirror-single-instance.test.ts checks the installed dependency graph and highlights sample code through the editor's real language dependencies. GitHub Actions owns regeneration of pnpm-lock.yaml.