You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(perps): add MM Pay token metrics and cancel trade event tracking (#27109)
## **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**
```gherkin
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**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!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.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9a82c62. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
// Pay with any token: trade_with_token (boolean); when true, include mm_pay_token_selected and mm_pay_network_selected
167
+
// Pay with any token: trade_with_token (boolean); when true, include mm_pay_token_selected and mm_pay_network_selected; when false (Perps balance), include mm_pay_token_selected: "Perps Balance"
-`input_method` (optional): How value was entered: `'slider' | 'keyboard' | 'preset' | 'manual' | 'percentage_button'`
163
163
-`limit_price` (optional): Limit order price (for limit orders) (number)
164
164
-`trade_with_token` (optional): Whether the user paid with a token other than Perps balance (boolean)
165
-
-`mm_pay_token_selected` (optional): Token symbol selected for pay-with (e.g. `'USDC'`), included when `trade_with_token` is true
165
+
-`mm_pay_token_selected` (optional): Token symbol selected for pay-with (e.g. `'USDC'`); when `trade_with_token` is true, the selected token symbol; when user uses Perps balance, `'Perps Balance'`
166
166
-`mm_pay_network_selected` (optional): Network/chain for pay-with (e.g. `'ethereum'`), included when `trade_with_token` is true
167
167
-`error_message` (optional): Error description when status is 'failed'
0 commit comments