refactor(analytics): migrate perps events#43890
Conversation
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/perps (10 files, +200 -294)
|
Builds ready [5087e2c]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 9 warn · 🔴 1 fail)
Bundle size diffs
|
5087e2c to
0c4c4c7
Compare
|
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. |
Builds ready [0c4c4c7]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs
|
0c4c4c7 to
7b76ec9
Compare
7b76ec9 to
d0f340b
Compare
d0f340b to
5de410d
Compare
5de410d to
ddb841c
Compare
ddb841c to
fc30393
Compare
Builds ready [fc30393] [reused from 7b76ec9]
⚡ Performance Benchmarks (Total: 🟢 10 pass · 🟡 8 warn · 🔴 0 fail)
Bundle sizes
|
fc30393 to
c4ab57a
Compare
c4ab57a to
296e4bd
Compare
b0c45a4 to
6b735ef
Compare
Builds ready [6b735ef]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs
|
Use segment page title for SupportLinkClicked and ExternalLinkClicked properties.location to match legacy contextPropsIntoEventProperties. Co-authored-by: Cursor <cursoragent@cursor.com>
…ranch Reconcile with main while keeping analytics migration only: restore terminalApiUrl wiring and AuthenticatedUserStorageService messenger delegates that were accidentally dropped on the stale branch base. Co-authored-by: Cursor <cursoragent@cursor.com>
Restore analytics trackEvent delegation test for perps init, fix support-learn location parity via real /perps page title, and revert unrelated perps toast presentation styling changes. Co-authored-by: Cursor <cursoragent@cursor.com>
Move analytics trackPerpsEvent delegation test back to the slot of the former MetaMetricsController trackEvent test in perps init tests. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Migrates Perps-domain analytics from legacy MetaMetrics trackEvent payloads (and MetaMetricsContext / messenger delegation) to the new createEventBuilder + trackEvent API via useAnalytics() in the UI and app/scripts/controllers/analytics in the background, aligning this domain with the umbrella analytics migration.
Changes:
- UI: refactors Perps UI event tracking to use
useAnalytics()/createEventBuilder(including theusePerpsEventTrackinghook and Perps support interactions). - Background: removes Perps’ direct messenger delegation to
MetaMetricsController:trackEventand routes Perps infrastructure metrics throughcontrollers/analytics. - Tests: updates Perps UI/background tests to mock
useAnalytics()/controllers/analyticsand assert the new event shape (name,properties.category, etc.).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| app/scripts/controllers/perps/infrastructure.ts | Routes Perps infrastructure metrics through controllers/analytics using createEventBuilder + trackEvent. |
| app/scripts/controllers/perps/infrastructure.test.ts | Updates expectations/mocking for the new analytics builder + track path. |
| app/scripts/messenger-client-init/perps-controller-init.ts | Removes MetaMetricsController:trackEvent delegation wiring from Perps controller init. |
| app/scripts/messenger-client-init/perps-controller-init.test.ts | Adjusts init tests to validate delegation through AnalyticsController-backed tracking instead of messenger trackEvent. |
| app/scripts/messenger-client-init/messengers/perps-controller-messenger.ts | Removes MetaMetricsController:trackEvent from allowed actions/action types for the Perps controller messenger. |
| app/scripts/messenger-client-init/messengers/perps-controller-messenger.test.ts | Updates allowed-action assertions to match the messenger change. |
| ui/hooks/perps/usePerpsEventTracking.ts | Migrates Perps hook to build events with createEventBuilder and send via useAnalytics().trackEvent. |
| ui/hooks/perps/usePerpsEventTracking.test.tsx | Updates hook tests to mock useAnalytics() and assert the new built event payload shape. |
| ui/components/app/perps/perps-support-learn/perps-support-learn.tsx | Migrates Support/Feedback link tracking to useAnalytics() with built events and Perps route-derived location. |
| ui/components/app/perps/perps-support-learn/perps-support-learn.test.tsx | Updates tests to mock useAnalytics() and assert new tracking payloads on the Perps route. |
| ui/components/app/perps/perps-tutorial-modal/PerpsTutorialModal.test.tsx | Updates tutorial modal tests to mock useAnalytics() instead of providing MetaMetricsContext. |
| ui/components/app/perps/perps-view.test.tsx | Migrates Perps view tests to mock useAnalytics() and validate name/properties.category assertions. |
| ui/pages/perps/perps-order-entry-page.tsx | Updates a comment to reference useAnalytics (behavior unchanged). |
| ui/pages/perps/perps-order-entry-page.test.tsx | Migrates order entry analytics test coverage to the new useAnalytics() event shape. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Builds ready [0913f4d] [reused from 422a1b7]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 7 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
geositta
left a comment
There was a problem hiding this comment.
Approve. This gives us a cleaner boundary for the upcoming core Perps analytics integration.
@gauthierpetetin One thing I have in mind for the next step: core now treats the Perps analytics contract as the source of truth in @metamask/perps-controller, while extension is still on the older package version and local constants mirror.



Description
Sub-PR of umbrella tracker #43885.
Migrates MetaMetrics
trackEventcall sites in this CODEOWNERS domain tocreateEventBuilder+trackEventviauseAnalytics()(UI) orapp/scripts/controllers/analytics(background).Dependency note: Can merge in parallel with other domain PRs after PR1.
Files in this PR: 22
Changelog
CHANGELOG entry: null
Related issues
Part of analytics migration umbrella: #43885
Manual testing steps
yarn start.Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches analytics plumbing across background and UI; event property shape and
locationsourcing change for some clicks, which can affect dashboards but not trading or funds.Overview
Migrates perps analytics from legacy MetaMetrics (
MetaMetricsContext/MetaMetricsController:trackEvent) tocreateEventBuilder+trackEventviauseAnalytics()in the UI andapp/scripts/controllers/analyticsin the background.Background:
createPerpsInfrastructureno longer accepts an injectedtrackEvent;trackPerpsEventbuilds events with category and timestamp and calls the shared analytics module.PerpsControllerInitdrops the messenger bridge toMetaMetricsController:trackEvent, and the perps controller messenger allowed actions no longer include that action.UI:
usePerpsEventTrackingandPerpsSupportLearnuseuseAnalytics; support/feedback link events useuseSegmentContextpage title forlocationinstead of a hardcoded string (tests expectPerps Tabon/perps). Related perps UI tests mockuseAnalyticsand assert the new payload shape (name,properties.category, etc.).Reviewed by Cursor Bugbot for commit 0913f4d. Bugbot is set up for automated code reviews on this repo. Configure here.