Skip to content

fix(analytics): attribute manteca KYC lifecycle events to the initiated intent - #2478

Merged
jjramirezn merged 1 commit into
devfrom
fix/manteca-kyc-analytics-attribution
Jul 22, 2026
Merged

fix(analytics): attribute manteca KYC lifecycle events to the initiated intent#2478
jjramirezn merged 1 commit into
devfrom
fix/manteca-kyc-analytics-attribution

Conversation

@jjramirezn

@jjramirezn jjramirezn commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

LATAM (Manteca) KYC completions were being logged as kyc_approved with region_intent: None instead of manteca_kyc_completed (same for abandons → kyc_abandoned). The Manteca entry points (MantecaAddMoney, qr-pay, withdraw/manteca, MantecaFlowManager) instantiate useMultiPhaseKycFlow({}) and pass 'LATAM' only as a call-time override to handleInitiateKyc, while the completion/abandon/rejected/submitted captures read the (undefined) hook-level regionIntent.

Impact: manteca_kyc_initiatedmanteca_kyc_completed funnels systematically undercount successes. This paged a false "🔴 Funnel dead: manteca-kyc — 25 attempts, 0 successes" alert on 2026-07-22 while both affected users were in fact ACTIVE in the backend (one success visible in PostHog as kyc_approved region_intent: None on /add-money/argentina at 16:54 UTC).

Fix: track the effective intent in a ref set inside handleInitiateKyc (which already computes overrideIntent ?? regionIntent) and let it win over the prop in all lifecycle captures.

Risks / breaking changes

  • Analytics-only; no flow behavior changes. No cross-repo impact.
  • Sibling change (separate PR in crispy): the funnel-pulse sentinel switches to distinct-person counting.

QA

  • npm run typecheck clean; jest 2008 passed (1 pre-existing failure in add-money-states.test.tsx "loaded EVM deposit shows QR code and address", also red on clean dev — unrelated).
  • Verify post-deploy in PostHog: completions via /add-money/* LATAM flows emit manteca_kyc_completed with region_intent: LATAM (previously only /profile/identity-verification did).

Summary by CodeRabbit

  • Analytics
    • Improved KYC analytics accuracy by attributing events to the most recently selected region intent.
    • Updated reporting across KYC completion, rejection, submission, and abandonment events.

…ed intent

Manteca entry points (MantecaAddMoney, qr-pay, withdraw/manteca,
MantecaFlowManager) instantiate useMultiPhaseKycFlow({}) and pass 'LATAM'
only as an override to handleInitiateKyc, so completion/abandon captures
read the undefined hook-level regionIntent: LATAM successes fired as
kyc_approved with region_intent None and abandons as kyc_abandoned. That
made manteca_kyc_completed undercount and paged a false 'Funnel dead:
manteca-kyc' alert (2026-07-22). Track the last initiated intent in a ref
and let it win over the prop for all lifecycle captures.
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
peanut-wallet Ready Ready Preview, Comment Jul 22, 2026 6:27pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

useMultiPhaseKycFlow now records the latest initiated KYC region intent and uses it for PostHog attribution across completion, rejection, submission, and abandonment events, falling back to the hook’s regionIntent when no override exists.

Changes

KYC intent analytics

Layer / File(s) Summary
Track the initiated KYC intent
src/hooks/useMultiPhaseKycFlow.ts
Stores the selected initiation intent, including overrides, in lastIntentRef.
Attribute lifecycle analytics
src/hooks/useMultiPhaseKycFlow.ts
Uses the effective intent for completed, rejected, submitted, and abandoned PostHog events and LATAM event selection.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: hugo0, kushagrasarathe

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the analytics attribution fix for Manteca KYC lifecycle events and matches the main change.
✨ 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/manteca-kyc-analytics-attribution

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

@github-actions

Copy link
Copy Markdown
Contributor

Code-analysis diff

Painscore total: 6233.55 → 6233.75 (+0.2)
Findings: -1 net (+3 new, -4 resolved)

🆕 New findings (3)

  • critical complexity — src/hooks/useMultiPhaseKycFlow.ts — CC 66, MI 57.44, SLOC 330
  • medium high-mdd — src/hooks/useMultiPhaseKycFlow.ts:98 — useMultiPhaseKycFlow: MDD 120.6 (uses across many lines from declarations)
  • medium hotspot — src/hooks/useMultiPhaseKycFlow.ts — 24 commits, +551/-115 lines since 6 months ago

✅ Resolved (4)

  • src/hooks/useMultiPhaseKycFlow.ts — CC 66, MI 57.68, SLOC 325
  • src/hooks/useMultiPhaseKycFlow.ts:98 — useMultiPhaseKycFlow: MDD 116.0 (uses across many lines from declarations)
  • src/app/actions/sumsub.ts — 24 commits, +220/-68 lines since 6 months ago
  • src/hooks/useMultiPhaseKycFlow.ts:264 — : MDD 10.0 (uses across many lines from declarations)

@github-actions

Copy link
Copy Markdown
Contributor

🧪 UI test report — ✅ all green

Suites

  • unit: 2012 ran, 0 failed, 0 skipped, 28.6s

📊 Coverage (unit)

metric %
statements 59.8%
branches 43.4%
functions 48.7%
lines 60.1%
⏱ 10 slowest test cases
time test
2.8s src/components/Card/share-asset/__tests__/shareAssetLayout.test.ts › never places two stickers in heavy overlap (broad seed sweep)
1.0s src/utils/__tests__/demo-api.test.ts › isDemoMode() is false when not running under Capacitor
0.3s src/components/Card/share-asset/__tests__/shareAssetLayout.test.ts › every sticker stays within canvas at any count
0.3s src/app/(mobile-ui)/withdraw/__tests__/withdraw-states.test.tsx › Bank withdrawal keeps the $1 minimum for sub-$1 amounts
0.2s src/app/actions/__tests__/api-headers-extended.test.ts › should not include apiKey in validateInviteCode body
0.2s src/app/actions/__tests__/api-headers.test.ts › should include Content-Type in validateInviteCode
0.2s src/utils/__tests__/demo-balance.test.ts › starts at the full balance on a fresh install and stamps a timestamp
0.2s src/components/Card/share-asset/__tests__/shareAssetLayout.test.ts › keeps stickers off the username pill (final pass respects the keep-out)
0.1s src/utils/__tests__/url.utils.test.ts › uses the public BASE_URL in Capacitor, not the localhost WebView origin
0.1s src/utils/__tests__/demo-balance.test.ts › keeps a spent-down balance across a cold start within the TTL
📍 Inline annotations are in the **Unit test report** check above. Coverage artifact: `coverage-unit`. Generated by `.github/workflows/tests.yml`.

@jjramirezn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

🧹 Nitpick comments (1)
src/hooks/useMultiPhaseKycFlow.ts (1)

159-162: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for override-only intent attribution.

Test a hook with no regionIntent, initiate with 'LATAM', and assert completion captures MANTECA_KYC_COMPLETED with region_intent: 'LATAM'.

🤖 Prompt for 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.

In `@src/hooks/useMultiPhaseKycFlow.ts` around lines 159 - 162, Add regression
coverage for the completion path in useMultiPhaseKycFlow: render the hook
without regionIntent, initiate the flow with 'LATAM', and assert PostHog
captures ANALYTICS_EVENTS.MANTECA_KYC_COMPLETED with region_intent set to
'LATAM'.
🤖 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.

Nitpick comments:
In `@src/hooks/useMultiPhaseKycFlow.ts`:
- Around line 159-162: Add regression coverage for the completion path in
useMultiPhaseKycFlow: render the hook without regionIntent, initiate the flow
with 'LATAM', and assert PostHog captures ANALYTICS_EVENTS.MANTECA_KYC_COMPLETED
with region_intent set to 'LATAM'.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f20d6493-9226-4a1a-9d02-94f31de14013

📥 Commits

Reviewing files that changed from the base of the PR and between 74f02f5 and b5a21b0.

📒 Files selected for processing (1)
  • src/hooks/useMultiPhaseKycFlow.ts

@jjramirezn
jjramirezn marked this pull request as ready for review July 22, 2026 18:30
@jjramirezn
jjramirezn merged commit 15df185 into dev Jul 22, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant