Skip to content

fix(analytics): report account_created from the client - #3532

Merged
ygrishajev merged 1 commit into
mainfrom
fix/analytics-account-created-client-side
Jul 28, 2026
Merged

fix(analytics): report account_created from the client#3532
ygrishajev merged 1 commit into
mainfrom
fix/analytics-account-created-client-side

Conversation

@ygrishajev

@ygrishajev ygrishajev commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Why

account_created was the only onboarding-funnel event emitted from the backend (on user registration), while trial_started, onboarding_deploy_click, and the rest fire from the browser. Because the two sources never shared a clock, device id, or session, Amplitude stitched them together inconsistently — events showed up out of order and the very first funnel step (account_created → trial_started) reported inflated drop-off even though nothing was actually dropping off there.

What

  • Report account_created from the client. POST /v1/register-user now returns isNewUser (from the repository's wasInserted); the server-side emission is removed, so the event has a single source.
  • Hand the signal to the browser. The OAuth ([...auth0]) and passwordless (email-code-verify) auth callbacks set a short-lived, one-shot cookie when isNewUser is true.
  • Fire it once, in the user's own session. A mounted AccountCreatedTracker consumes the cookie — on mount for full-reload landings (OAuth) and on routeChangeComplete for client-side ones (passwordless) — emits account_created with the browser's device id/session, and clears the cookie.
  • Flush high-value click events before navigation. The onboarding deploy CTA now flushes the Amplitude queue right after tracking, so the click event isn't lost to the batch window when the page transitions.

The register-user response change is additive (a new isNewUser field), so it's backward-compatible — no breaking production contract.

Out of scope: onboarding_account_created (a separate onboarding-flow event) and the password-signup path (not an active signup method) are left untouched.

Summary by CodeRabbit

  • New Features
    • Registration responses now include an isNewUser boolean.
    • Added “account created” analytics tracking driven by a one-time cookie during signup.
    • Introduced analytics flushing around key navigation/actions to improve event delivery.
  • Bug Fixes
    • Prevented “account created” analytics from being emitted when the user already existed.
    • Improved analytics timing across authentication callbacks and onboarding redirects.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cd389b12-8e49-431d-9e68-90579dc3d222

📥 Commits

Reviewing files that changed from the base of the PR and between a37014f and 19cba3c.

⛔ Files ignored due to path filters (1)
  • apps/api/test/functional/__snapshots__/docs.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (20)
  • apps/api/src/core/services/analytics/analytics.service.ts
  • apps/api/src/user/controllers/user/user.controller.ts
  • apps/api/src/user/routes/register-user/register-user.router.ts
  • apps/api/src/user/services/user/user.service.spec.ts
  • apps/api/src/user/services/user/user.service.ts
  • apps/api/swagger/openapi.json
  • apps/deploy-web/src/components/analytics/AccountCreatedTracker/AccountCreatedTracker.spec.tsx
  • apps/deploy-web/src/components/analytics/AccountCreatedTracker/AccountCreatedTracker.tsx
  • apps/deploy-web/src/components/onboarding-picker/OnboardingPickerPage.spec.tsx
  • apps/deploy-web/src/components/onboarding-picker/OnboardingPickerPage.tsx
  • apps/deploy-web/src/lib/analytics/account-created-cookie.spec.ts
  • apps/deploy-web/src/lib/analytics/account-created-cookie.ts
  • apps/deploy-web/src/lib/nextjs/api-routes-specs/auth-email-code-verify.spec.ts
  • apps/deploy-web/src/pages/_app.tsx
  • apps/deploy-web/src/pages/api/auth/[...auth0].ts
  • apps/deploy-web/src/pages/api/auth/email-code-verify.ts
  • apps/deploy-web/src/services/analytics/analytics.service.spec.ts
  • apps/deploy-web/src/services/analytics/analytics.service.ts
  • apps/deploy-web/src/services/session/session.service.spec.ts
  • apps/deploy-web/src/services/session/session.service.ts
🚧 Files skipped from review as they are similar to previous changes (16)
  • apps/api/src/user/routes/register-user/register-user.router.ts
  • apps/deploy-web/src/lib/analytics/account-created-cookie.spec.ts
  • apps/deploy-web/src/lib/analytics/account-created-cookie.ts
  • apps/deploy-web/src/components/onboarding-picker/OnboardingPickerPage.tsx
  • apps/deploy-web/src/components/analytics/AccountCreatedTracker/AccountCreatedTracker.tsx
  • apps/deploy-web/src/services/analytics/analytics.service.ts
  • apps/deploy-web/src/pages/_app.tsx
  • apps/deploy-web/src/components/onboarding-picker/OnboardingPickerPage.spec.tsx
  • apps/api/swagger/openapi.json
  • apps/deploy-web/src/services/session/session.service.ts
  • apps/api/src/core/services/analytics/analytics.service.ts
  • apps/deploy-web/src/services/analytics/analytics.service.spec.ts
  • apps/deploy-web/src/services/session/session.service.spec.ts
  • apps/deploy-web/src/lib/nextjs/api-routes-specs/auth-email-code-verify.spec.ts
  • apps/api/src/user/services/user/user.service.spec.ts
  • apps/api/src/user/services/user/user.service.ts

📝 Walkthrough

Walkthrough

Changes

Account creation analytics

Layer / File(s) Summary
Registration response contract
apps/api/src/user/services/user/user.service.ts, apps/api/src/user/controllers/user/user.controller.ts, apps/api/src/user/routes/register-user/register-user.router.ts, apps/api/swagger/openapi.json, apps/api/src/core/services/analytics/analytics.service.ts, apps/api/src/user/services/user/user.service.spec.ts
Registration now returns and exposes isNewUser; server-side account_created tracking is removed from the API analytics contract.
Session propagation and cookie creation
apps/deploy-web/src/services/session/*, apps/deploy-web/src/pages/api/auth/*, apps/deploy-web/src/lib/analytics/account-created-cookie*, apps/deploy-web/src/lib/nextjs/api-routes-specs/auth-email-code-verify.spec.ts
Session creation propagates isNewUser, and authentication routes set a short-lived account-created cookie only for newly created users.
Browser event consumption and analytics flushing
apps/deploy-web/src/components/analytics/AccountCreatedTracker/*, apps/deploy-web/src/services/analytics/*, apps/deploy-web/src/pages/_app.tsx
The application consumes the cookie on mount or route completion, tracks and flushes account_created, and mounts the tracker globally.
Navigation analytics flushes
apps/deploy-web/src/components/onboarding-picker/*
Onboarding deployment actions flush analytics around navigation, with tests covering template and custom-image flows.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: stalniy

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/analytics-account-created-client-side

Comment @coderabbitai help to get the list of available commands.

@ygrishajev
ygrishajev force-pushed the fix/analytics-account-created-client-side branch from 780432c to a37014f Compare July 28, 2026 13:31
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.37%. Comparing base (89cf8cc) to head (19cba3c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3532      +/-   ##
==========================================
- Coverage   74.29%   73.37%   -0.93%     
==========================================
  Files        1148     1060      -88     
  Lines       29827    27510    -2317     
  Branches     7459     7013     -446     
==========================================
- Hits        22161    20186    -1975     
+ Misses       6766     6454     -312     
+ Partials      900      870      -30     
Flag Coverage Δ *Carryforward flag
api 87.52% <100.00%> (-0.01%) ⬇️
deploy-web 63.86% <100.00%> (+0.08%) ⬆️
log-collector ?
notifications 93.84% <ø> (ø) Carriedforward from 89cf8cc
provider-console 81.38% <ø> (ø) Carriedforward from 89cf8cc
provider-inventory ?
provider-proxy 88.17% <ø> (ø) Carriedforward from 89cf8cc
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...i/src/core/services/analytics/analytics.service.ts 100.00% <ø> (ø)
...s/api/src/user/controllers/user/user.controller.ts 42.42% <100.00%> (ø)
apps/api/src/user/services/user/user.service.ts 94.82% <ø> (-0.18%) ⬇️
...cs/AccountCreatedTracker/AccountCreatedTracker.tsx 100.00% <100.00%> (ø)
...ponents/onboarding-picker/OnboardingPickerPage.tsx 96.49% <100.00%> (+0.12%) ⬆️
...oy-web/src/lib/analytics/account-created-cookie.ts 100.00% <100.00%> (ø)
...deploy-web/src/pages/api/auth/email-code-verify.ts 100.00% <100.00%> (ø)
...oy-web/src/services/analytics/analytics.service.ts 94.59% <100.00%> (+0.30%) ⬆️
...deploy-web/src/services/session/session.service.ts 86.17% <100.00%> (ø)

... and 91 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread apps/api/src/user/routes/register-user/register-user.router.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/deploy-web/src/components/onboarding-picker/OnboardingPickerPage.spec.tsx`:
- Around line 346-362: Update the deploy-handler tests in
OnboardingPickerPage.spec.tsx to capture the navigation mock and assert that
analyticsService.flush was invoked before push or link navigation. Use async act
and await the handler when flushing is asynchronous, covering both the
deployment card and custom-image link flows.

In `@apps/deploy-web/src/services/analytics/analytics.service.ts`:
- Line 151: Update the Amplitude type and AnalyticsService.flush()
implementation to preserve and return Amplitude’s awaitable flush result instead
of discarding it. Then await AnalyticsService.flush() in the onboarding and
account-created flow call sites so navigation occurs only after the event send
completes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 13047afe-e5a2-4b52-975f-a470fc86c2bb

📥 Commits

Reviewing files that changed from the base of the PR and between c5f6a63 and a37014f.

📒 Files selected for processing (20)
  • apps/api/src/core/services/analytics/analytics.service.ts
  • apps/api/src/user/controllers/user/user.controller.ts
  • apps/api/src/user/routes/register-user/register-user.router.ts
  • apps/api/src/user/services/user/user.service.spec.ts
  • apps/api/src/user/services/user/user.service.ts
  • apps/api/swagger/openapi.json
  • apps/deploy-web/src/components/analytics/AccountCreatedTracker/AccountCreatedTracker.spec.tsx
  • apps/deploy-web/src/components/analytics/AccountCreatedTracker/AccountCreatedTracker.tsx
  • apps/deploy-web/src/components/onboarding-picker/OnboardingPickerPage.spec.tsx
  • apps/deploy-web/src/components/onboarding-picker/OnboardingPickerPage.tsx
  • apps/deploy-web/src/lib/analytics/account-created-cookie.spec.ts
  • apps/deploy-web/src/lib/analytics/account-created-cookie.ts
  • apps/deploy-web/src/lib/nextjs/api-routes-specs/auth-email-code-verify.spec.ts
  • apps/deploy-web/src/pages/_app.tsx
  • apps/deploy-web/src/pages/api/auth/[...auth0].ts
  • apps/deploy-web/src/pages/api/auth/email-code-verify.ts
  • apps/deploy-web/src/services/analytics/analytics.service.spec.ts
  • apps/deploy-web/src/services/analytics/analytics.service.ts
  • apps/deploy-web/src/services/session/session.service.spec.ts
  • apps/deploy-web/src/services/session/session.service.ts

Comment thread apps/deploy-web/src/services/analytics/analytics.service.ts
@ygrishajev
ygrishajev force-pushed the fix/analytics-account-created-client-side branch from a37014f to ce99180 Compare July 28, 2026 13:50
account_created was emitted server-side on user registration while every other funnel event
fires from the browser, so they never shared a clock, device id, or session. In Amplitude that
skew showed up as out-of-order events and inflated drop-off at the first funnel step.

Move it to the client: register-user now returns isNewUser, the OAuth and passwordless auth
callbacks hand that signal to the browser via a one-shot cookie, and a mounted tracker fires
account_created once in the user's own session context. The server-side emission is removed.

Also flush high-value click events (the onboarding deploy CTA) immediately instead of leaving
them in the Amplitude batch queue, where a fast page transition could drop them.
@ygrishajev
ygrishajev force-pushed the fix/analytics-account-created-client-side branch from ce99180 to 19cba3c Compare July 28, 2026 13:51
@ygrishajev
ygrishajev enabled auto-merge July 28, 2026 14:00
Comment thread apps/api/swagger/openapi.json
@ygrishajev
ygrishajev added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit d92868b Jul 28, 2026
58 checks passed
@ygrishajev
ygrishajev deleted the fix/analytics-account-created-client-side branch July 28, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants