Skip to content

Conversation

@Jon-edge
Copy link
Collaborator

@Jon-edge Jon-edge commented Feb 6, 2026

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes

Dependencies

None

Description

Fixes the P1 Moonpay Buy_Success PostHog tracking bug where incorrect values were intermittently reported. The root cause was identified as the RampDeeplinkManager using a single-listener slot that got silently overwritten when a new quote was initiated before the previous transaction's deeplink arrived. This root cause is not confirmed, these changes are a theory, with handling and canary reporting to ensure we at least don't further pollute our tracking with inflated buy volume and report if the regression persists.

Commit 1: Fix deeplink handler overwrite race condition

Replace the single listener field in RampDeeplinkManager with a token-keyed Map. Each register() call now returns a unique token for targeted cleanup, preventing one handler from overwriting another. handleDeeplink() matches the most recently registered listener for the given providerId + direction.

Updates all callers (webViewUtils, moonpayRampPlugin, revolutRampPlugin, paybisRampPlugin) to use the token-based API.

Commit 2: Add Moonpay buy tracking verification via transactions API

When the Moonpay buy deeplink fires, query Moonpay's GET /v1/transactions/:id API to verify the actual transaction amounts:

  • API succeeds: Log Buy_Success with API-verified values and include both closure + API values as diagnostic properties. If they differ, also log a Buy_Tracking_Mismatch event.
  • API fails: Skip Buy_Success entirely (unverifiable) and log Buy_Tracking_Mismatch with the closure values and failure reason.

If the deeplink manager fix works correctly, Buy_Tracking_Mismatch should never appear in PostHog. If it does, we know there's another issue — but the Buy_Success data stays clean.

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

No visual changes in this PR.


Note

Medium Risk
Touches shared deeplink/webview flow across multiple ramp providers and changes analytics emission behavior for Moonpay, so regressions could impact ramp completion handling or tracking accuracy.

Overview
Prevents ramp deeplink callbacks from being silently overwritten by replacing the single RampDeeplinkManager listener with a tokenized Map, updating ramp plugins and webViewUtils to store per-quote tokens and reliably unregister on close/errors.

For Moonpay buys, adds a verification step that fetches GET /v1/transactions/:id and logs Buy_Success using API-verified fiat/crypto amounts (with diagnostic fields), otherwise emits a new Buy_Tracking_Mismatch event when verification fails or values differ. Updates CHANGELOG.md accordingly.

Written by Cursor Bugbot for commit 0dec727. This will update automatically on new commits. Configure here.


Copy link

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

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: ba11f8e5ca

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

@Jon-edge Jon-edge force-pushed the jon/fix/buy-tracking-race-condition branch from ba11f8e to 4a1d17d Compare February 6, 2026 23:51
@Jon-edge Jon-edge force-pushed the jon/fix/buy-tracking-race-condition branch from 4a1d17d to b8494fe Compare February 7, 2026 02:03
@Jon-edge Jon-edge force-pushed the jon/fix/buy-tracking-race-condition branch from b8494fe to d905ce7 Compare February 7, 2026 02:18
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Replace the single-listener slot in RampDeeplinkManager with a
token-keyed Map. Previously, each register() call silently overwrote
the previous handler, causing stale closure-captured values to be
used when a delayed deeplink arrived after the user initiated a new
quote. Now each registration returns a unique token for targeted
cleanup, and handleDeeplink matches the most recently registered
listener for the given providerId + direction.

Update all callers (webViewUtils, moonpay, revolut, paybis) to
capture and pass the token for unregistration.
When the Moonpay buy deeplink handler fires, query the Moonpay
transactions API to fetch the actual transaction amounts and use
those as the source of truth for Buy_Success tracking.

If the API query succeeds, log Buy_Success with API values and
include both closure and API values as diagnostic properties. If
closure values differ from API values, also log a separate
Buy_Tracking_Mismatch event.

If the API query fails, skip Buy_Success entirely (values are
unverifiable) and log Buy_Tracking_Mismatch with the closure values
and the failure reason.

This serves as both a correctness guarantee for PostHog data and
a diagnostic signal — if Buy_Tracking_Mismatch events appear after
the deeplink manager fix, it indicates an additional unknown issue.
@Jon-edge Jon-edge force-pushed the jon/fix/buy-tracking-race-condition branch from d905ce7 to 0dec727 Compare February 12, 2026 22:59
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