Skip to content

feat(perps): add MM Pay token metrics and cancel trade event tracking#27109

Merged
michalconsensys merged 4 commits into
mainfrom
chore/perps/mm-pay-token-metrics
Mar 10, 2026
Merged

feat(perps): add MM Pay token metrics and cancel trade event tracking#27109
michalconsensys merged 4 commits into
mainfrom
chore/perps/mm-pay-token-metrics

Conversation

@michalconsensys
Copy link
Copy Markdown
Contributor

@michalconsensys michalconsensys commented Mar 6, 2026

Description

This PR adds comprehensive event tracking for MM Pay token metrics in the Perps trading flow. The changes include:

  1. MM Pay Token Metrics Enhancement: When users trade using their Perps balance (instead of paying with a token), the mm_pay_token_selected property now includes the value 'Perps Balance' in trade transaction events. This provides complete visibility into payment method selection, whether users pay with tokens or use their Perps balance.

  2. Cancel Trade with Token Event Tracking: Added event tracking for the cancel trade with token flow:

    • PERPS_UI_INTERACTION event with interaction_type: 'cancel_trade_with_token' when the user cancels a trade
    • PERPS_SCREEN_VIEWED event with screen_type: 'cancel_trade_with_token_toast' when the "taking longer" toast is displayed

These metrics enable better analytics on user behavior, payment method preferences, and cancellation patterns in the Perps trading experience.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2616

Manual testing steps

Feature: MM Pay token metrics and cancel trade tracking

  Scenario: user trades with Perps balance
    Given user has a Perps account with available balance
    When user places a trade order using Perps balance (not paying with a token)
    Then the PERPS_TRADE_TRANSACTION event should include mm_pay_token_selected: "Perps Balance"

  Scenario: user cancels trade with token during deposit
    Given user has initiated a trade order with token payment
    And the deposit is taking longer than expected
    When the "taking longer" toast appears
    Then the PERPS_SCREEN_VIEWED event should be tracked with screen_type: "cancel_trade_with_token_toast"
    And when user taps the cancel button
    Then the PERPS_UI_INTERACTION event should be tracked with interaction_type: "cancel_trade_with_token"

Screenshots/Recordings

Before

N/A (analytics/metrics changes, no UI changes)

After

N/A (analytics/metrics changes, no UI changes)

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Low Risk
Low risk: changes are limited to MetaMetrics analytics properties/events and associated constants/tests, with no changes to order execution behavior beyond emitting additional tracking calls.

Overview
Adds new Perps MetaMetrics tracking for the deposit+order cancellation flow: emits PERPS_SCREEN_VIEWED when the "deposit taking longer" cancel toast is shown and PERPS_UI_INTERACTION when the user taps cancel.

Extends PERPS_TRADE_TRANSACTION analytics so when trackingData is present but tradeWithToken is false, mm_pay_token_selected is explicitly reported as "Perps Balance" (applied in both usePerpsOrderExecution and TradingService). Updates Perps event constants, tests, and the Perps metametrics reference docs accordingly.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-perps Perps team label Mar 6, 2026
@github-actions github-actions Bot added the size-M label Mar 6, 2026
@michalconsensys michalconsensys marked this pull request as ready for review March 6, 2026 09:27
@michalconsensys michalconsensys requested a review from a team as a code owner March 6, 2026 09:27
Comment thread app/components/UI/Perps/hooks/usePerpsOrderExecution.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR adds analytics/MetaMetrics tracking enhancements to the Perps (perpetuals trading) feature. The changes include:

  1. usePerpsOrderDepositTracking.ts: Added tracking for cancel trade interactions and "taking longer" toast views
  2. usePerpsOrderExecution.ts: Added tracking for mm_pay_token_selected: 'Perps Balance' when user pays with Perps balance
  3. TradingService.ts: Same enhancement for tracking Perps balance usage
  4. eventNames.ts: Added new event constants (CANCEL_TRADE_WITH_TOKEN, CANCEL_TRADE_WITH_TOKEN_TOAST, MM_PAY_TOKEN.PERPS_BALANCE)
  5. Test files: Added comprehensive unit tests for all new tracking
  6. Documentation: Updated MetaMetrics reference docs

These are purely analytics additions with no functional changes to trading logic. The risk is low as the changes only add event tracking calls. However, since they touch the Perps feature, SmokePerps is required. Per tag dependencies, SmokeWalletPlatform (Perps is a section in Trending) and SmokeConfirmations (Add Funds deposits are on-chain transactions) should also be included.

Performance Test Selection:
These changes are purely analytics/tracking additions that add lightweight MetaMetrics event calls. There are no changes to UI rendering, data loading, state management, or any performance-critical paths. The analytics calls are simple property additions to existing tracking events and do not impact app performance. No performance tests are needed.

View GitHub Actions results

Copy link
Copy Markdown
Contributor

@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, have a team admin enable autofix in the Cursor dashboard.

Comment thread app/controllers/perps/services/TradingService.ts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

⚠️ E2E Fixture Validation — Structural changes detected

Category Count
New keys 68
Missing keys 11
Type mismatches 0
Value mismatches 7 (informational)

The committed fixture schema is out of date. To update, comment:

@metamaskbot update-mobile-fixture

View full details | Download diff report

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 6, 2026

@michalconsensys michalconsensys added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 8ecb0f9 Mar 10, 2026
100 checks passed
@michalconsensys michalconsensys deleted the chore/perps/mm-pay-token-metrics branch March 10, 2026 08:25
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 10, 2026
@metamaskbot metamaskbot added the release-7.70.0 Issue or pull request that will be included in release 7.70.0 label Mar 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.70.0 Issue or pull request that will be included in release 7.70.0 size-M team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants