Files
PaperClipAI/tests
Devin FoleyandPaperclip 554227d926 fix(analytics): send queued product events after consent (#23328)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Hosted workspaces record browser product events for the onboarding
funnel.
> - The wizard can open before a visitor accepts browser analytics.
> - The capture path discarded those events and did not send them after
Accept.
> - This pull request holds pending events in page memory until the
visitor accepts.
> - The funnel can then retain the original event order and times.

## Linked Issues or Issue Description

**What happened?**

A visitor could open onboarding, complete steps, and then accept
analytics. The earlier browser events were missing. The funnel could
show server events such as workspace entry without the later onboarding
events, even when the visitor used the wizard.

**Expected behavior**

Hold structured product events while consent is pending. Send them once
after Accept, with their original order and timestamps. Discard them
after Decline or a change of user. Do not load PostHog before consent.

**Steps to reproduce**

1. Open a hosted workspace that requires analytics consent, with no
stored choice.
2. Open onboarding and complete a step before choosing Accept.
3. Choose Accept.
4. Confirm that the opening and step events reach the analytics client
once, with their original timestamps.

**Paperclip version or commit**

The fix is based on master at `630cf042302`. The tested PR revision is
`46df54b9ede8e5757f7af1a9d41b3c3593fe3430`.

**Deployment mode**

Hosted workspace browser analytics. The regression runs locally in
jsdom.

Related merged work: #22186 added browser consent; #22814 added
onboarding failure and chat events; #23315 enabled draft saving in the
naming step. A search found no duplicate PR for this queue fix.

## What Changed

- Track pending, granted, and denied consent in the browser analytics
state.
- Reuse the existing 50-event queue while consent is pending. Flush it
on Accept, after the client is ready.
- Clear pending events on Decline or a change of user. Apply user
identity before sending the queue.
- Add regression tests for the Accept button, onboarding events, queue
limits, and user changes. Document the queue lifetime.
- Remove the retired Runner support assertion that draft saving is
limited to step 4. PR #23315 added saving in both naming and connect
steps. Retain the other first-agent checks and the existing early-setup
browser test for name persistence and draft reuse.

## Verification

Environment: macOS arm64, Node.js v25.6.1, pnpm 9.15.4. Final local
checks use revision `46df54b9ede8e5757f7af1a9d41b3c3593fe3430`.

- The Accept-button regression failed before the fix: it expected the
earlier events but received an empty capture list.
- `pnpm exec vitest run --project @paperclipai/ui ui/src/lib/analytics
ui/src/components/ProductAnalyticsGate.test.tsx
ui/src/components/ProductAnalyticsSetting.test.tsx`: passed, 289 tests
across 9 files.
- `pnpm exec vitest run --config tests/runner-e2e/vitest.config.ts
tests/runner-e2e/chat-catalog-domains/identity-new-company-native.test.ts`:
passed, 51 tests. This suite first reproduced the stale draft-step
assertion from the failed CI job.
- `pnpm --filter @paperclipai/ui typecheck`: passed.
- `node scripts/check-test-budget.mjs --files
tests/runner-e2e/chat-catalog-domains/identity-new-company-native.test.ts
ui/src/components/ProductAnalyticsGate.test.tsx
ui/src/lib/analytics/onboarding-analytics.test.tsx`: passed.
- `git diff origin/master...HEAD --check`: passed.
- `pnpm verify`: exited 2 because `doc/cloud-browser-analytics.md`
triggers broader CI coverage. Focused checks above passed; the full
local suite was not run.
- GitHub Actions CI: [all planned suites
passed](https://github.com/paperclipai/paperclip/actions/runs/46519983330/job/142210329280)
on `46df54b9ede8e5757f7af1a9d41b3c3593fe3430`, including [typecheck and
release
registry](https://github.com/paperclipai/paperclip/actions/runs/46519983330/job/142208788257),
[build](https://github.com/paperclipai/paperclip/actions/runs/46519983330/job/142208788273),
Runner support, general tests, serialized tests, and browser E2E shards.
No live PostHog capture was checked.

- Greptile: [5/5 on the current
revision](https://github.com/paperclipai/paperclip/pull/23328#issuecomment-7292786296),
with a successful check and no unresolved review threads.

## Risks

- Accept now sends structured product events generated earlier in the
same page visit. Nothing is sent while consent is pending.
- The queue retains at most 50 events in memory. Further events are
dropped until it drains. Reloading the page loses the pending queue.
- This change does not record earlier page views or session replay.
PostHog still loads only after consent.

## Model Used

OpenAI `gpt-6.1-sol`, through the Codex harness in T3 Code, with xhigh
reasoning effort and shell/code tools. The harness does not expose the
context window size.

## 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
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-30 13:56:12 -08:00
..