Commit 43e2312
authored
feat(perps): add missing analytics properties and fix source propagation (#27493)
## **Description**
Adds missing Segment/Mixpanel analytics data across Perps events and
fixes source propagation issues to ensure accurate attribution in
analytics dashboards.
### Motivation
Several Perps analytics parameters were missing or inconsistent in
Mixpanel:
- `PERP SCREEN VIEWED` had many `(not set)` source values
- Transaction events (`TRADE`, `CLOSE`) lacked source and order value
tracking
- `PERP RISK MANAGEMENT` didn't differentiate TP vs SL vs both
- Reusable components navigated without passing `source`, leading to
implicit/missing attribution
- `source` was sometimes propagated from earlier screens in the
navigation chain instead of reflecting the current screen
### Solution
1. **New analytics properties**: `open_order`, `order_value`,
`market_category`, `error_type`, `action` (tp/sl/tpsl, flip variants),
and `explore` source
2. **Source propagation fix**: Screens now always set themselves as the
`source` rather than forwarding from previous screens (e.g., Market List
→ Market Details uses `perp_markets`, not `explore`)
3. **Explicit source passing**: Reusable components
(`PerpsMarketTypeSection`, `PerpsWatchlistMarkets`, `PerpsCard`) now
accept `source` as a prop from parent screens instead of navigating
without it
4. **Tooltip context**: `button_location` for tooltip "Got it" clicks
now includes screen-specific context
5. **Documentation**: Updated
`docs/perps/perps-metametrics-reference.md` with all new properties and
source ownership best practices
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2370
## **Manual testing steps**
```gherkin
Feature: Perps analytics source tracking
Scenario: Source reflects current screen when navigating through multiple screens
Given the user is on the Explore page
When the user taps "View All" on the Perps section to open Market List
And taps a market to open Market Details
And taps Long to open the Trading screen
Then PERPS_SCREEN_VIEWED for Market List has source = "explore"
And PERPS_SCREEN_VIEWED for Market Details has source = "perp_markets"
And PERPS_SCREEN_VIEWED for Trading has source = "perp_asset_screen"
Scenario: Reusable components pass source from parent screen
Given the user is on Perps Home
When the user taps a market in the Crypto section
Then PERPS_SCREEN_VIEWED for Market Details has source = "perps_home"
Scenario: Trade transaction includes order value and source
Given the user is on the Trading screen (from Market Details)
When the user places a market order for 0.1 BTC at $60,000
Then PERPS_TRADE_TRANSACTION includes source = "perp_asset_screen"
And PERPS_TRADE_TRANSACTION includes order_value = 6000
Scenario: Risk management event differentiates TP/SL
Given the user has an open BTC position
When the user sets both take profit and stop loss
Then PERPS_RISK_MANAGEMENT includes action = "tpsl"
Scenario: open_order parameter on screen viewed events
Given the user has 3 open orders
When the user views the Perps Home screen
Then PERPS_SCREEN_VIEWED includes open_order = 3
```
## **Screenshots/Recordings**
N/A — Analytics-only changes, no UI modifications.
### **Before**
N/A
### **After**
N/A
## **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]
> **Medium Risk**
> Mostly analytics instrumentation changes, but they touch navigation
params and `TradingService` tracking for trade/close events, so
incorrect wiring could skew attribution or event schemas in production
dashboards.
>
> **Overview**
> Improves Perps analytics attribution by **standardizing `source`
propagation** across navigation (market list/details/order/close flows),
including passing `source` explicitly through reusable components
(`PerpsMarketTypeSection`, `PerpsWatchlistMarkets`, tooltips, and
close-position routing).
>
> Adds missing MetaMetrics properties across key screen views and
transactions: `open_order`/`open_position` counts on more screens,
`market_category` on market list, `order_value` for trade and close
transactions, and more specific `action` values for TP/SL updates and
flip-position direction; updates tests and the Perps MetaMetrics
reference docs accordingly.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
36cf38e. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent e8d5375 commit 43e2312
25 files changed
Lines changed: 198 additions & 41 deletions
File tree
- app
- components
- UI/Perps
- Views
- PerpsClosePositionView
- PerpsHomeView
- PerpsMarketDetailsView
- PerpsMarketListView
- PerpsOrderBookView
- PerpsOrderView
- PerpsSelectModifyActionView
- PerpsTabView
- components
- PerpsBottomSheetTooltip
- PerpsMarketTypeSection
- PerpsWatchlistMarkets
- hooks
- types
- Views/TrendingView
- controllers/perps
- constants
- services
- docs/perps
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
| |||
392 | 395 | | |
393 | 396 | | |
394 | 397 | | |
| 398 | + | |
395 | 399 | | |
396 | 400 | | |
397 | 401 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
558 | 559 | | |
559 | 560 | | |
560 | 561 | | |
561 | | - | |
| 562 | + | |
562 | 563 | | |
563 | 564 | | |
564 | 565 | | |
| |||
Lines changed: 11 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
213 | 215 | | |
214 | 216 | | |
215 | 217 | | |
| |||
235 | 237 | | |
236 | 238 | | |
237 | 239 | | |
238 | | - | |
| 240 | + | |
239 | 241 | | |
240 | 242 | | |
241 | 243 | | |
| |||
257 | 259 | | |
258 | 260 | | |
259 | 261 | | |
260 | | - | |
| 262 | + | |
261 | 263 | | |
262 | 264 | | |
263 | 265 | | |
| |||
445 | 447 | | |
446 | 448 | | |
447 | 449 | | |
448 | | - | |
| 450 | + | |
449 | 451 | | |
450 | 452 | | |
451 | 453 | | |
| |||
465 | 467 | | |
466 | 468 | | |
467 | 469 | | |
468 | | - | |
| 470 | + | |
469 | 471 | | |
470 | 472 | | |
471 | 473 | | |
| |||
477 | 479 | | |
478 | 480 | | |
479 | 481 | | |
| 482 | + | |
480 | 483 | | |
481 | 484 | | |
482 | 485 | | |
| |||
487 | 490 | | |
488 | 491 | | |
489 | 492 | | |
| 493 | + | |
490 | 494 | | |
491 | 495 | | |
492 | 496 | | |
| |||
497 | 501 | | |
498 | 502 | | |
499 | 503 | | |
| 504 | + | |
500 | 505 | | |
501 | 506 | | |
502 | 507 | | |
| |||
507 | 512 | | |
508 | 513 | | |
509 | 514 | | |
| 515 | + | |
510 | 516 | | |
511 | 517 | | |
512 | 518 | | |
| |||
516 | 522 | | |
517 | 523 | | |
518 | 524 | | |
| 525 | + | |
519 | 526 | | |
520 | 527 | | |
521 | 528 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1423 | 1423 | | |
1424 | 1424 | | |
1425 | 1425 | | |
1426 | | - | |
| 1426 | + | |
1427 | 1427 | | |
1428 | 1428 | | |
1429 | 1429 | | |
| |||
1459 | 1459 | | |
1460 | 1460 | | |
1461 | 1461 | | |
1462 | | - | |
| 1462 | + | |
1463 | 1463 | | |
1464 | 1464 | | |
1465 | 1465 | | |
| |||
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
| 560 | + | |
560 | 561 | | |
561 | 562 | | |
562 | 563 | | |
| |||
620 | 621 | | |
621 | 622 | | |
622 | 623 | | |
623 | | - | |
| 624 | + | |
624 | 625 | | |
625 | 626 | | |
626 | 627 | | |
| |||
700 | 701 | | |
701 | 702 | | |
702 | 703 | | |
703 | | - | |
| 704 | + | |
704 | 705 | | |
705 | 706 | | |
706 | 707 | | |
| |||
865 | 866 | | |
866 | 867 | | |
867 | 868 | | |
868 | | - | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
869 | 873 | | |
870 | 874 | | |
871 | 875 | | |
| |||
1526 | 1530 | | |
1527 | 1531 | | |
1528 | 1532 | | |
| 1533 | + | |
1529 | 1534 | | |
1530 | 1535 | | |
1531 | 1536 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
108 | 111 | | |
109 | 112 | | |
110 | | - | |
| 113 | + | |
111 | 114 | | |
112 | 115 | | |
113 | 116 | | |
| |||
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
| 198 | + | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
| 778 | + | |
778 | 779 | | |
779 | 780 | | |
780 | 781 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| 301 | + | |
301 | 302 | | |
302 | 303 | | |
303 | 304 | | |
| |||
465 | 466 | | |
466 | 467 | | |
467 | 468 | | |
468 | | - | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
469 | 473 | | |
470 | 474 | | |
471 | 475 | | |
| |||
779 | 783 | | |
780 | 784 | | |
781 | 785 | | |
| 786 | + | |
782 | 787 | | |
783 | 788 | | |
784 | 789 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
| |||
1788 | 1789 | | |
1789 | 1790 | | |
1790 | 1791 | | |
| 1792 | + | |
1791 | 1793 | | |
1792 | 1794 | | |
1793 | 1795 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
| |||
0 commit comments