refactor(analytics): migrate core platform background events#43901
Conversation
Builds ready [dab3aeb]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 5 warn · 🔴 0 fail)
Bundle size diffs
|
|
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. |
dab3aeb to
6a8388f
Compare
Builds ready [6a8388f]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
6a8388f to
bbe9814
Compare
bbe9814 to
5d6bc0d
Compare
Builds ready [5d6bc0d] [reused from bbe9814]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 8 warn · 🔴 1 fail)
Bundle sizes
|
5d6bc0d to
c84b3a3
Compare
c84b3a3 to
ca12620
Compare
ca12620 to
1731104
Compare
Builds ready [1731104] [reused from bbe9814]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 8 warn · 🔴 1 fail)
Bundle sizes
|
1731104 to
446a0fb
Compare
Remove unrelated getSnapKeyring helper and restore main ConfigRegistry wiring that was accidentally dropped during conflict resolution. Co-authored-by: Cursor <cursoragent@cursor.com>
Restore integration tests from main to keep the analytics migration PR minimal. Unit tests cover the migrated tracking APIs. Co-authored-by: Cursor <cursoragent@cursor.com>
Revert unrelated snap subscription wiring, changePassword/estimateGas inlining, and leftover snap test mocks. Restore GMX referral tests and drop redundant duplicate trackEvent option args in direct call sites. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
createEvent still returns MetaMetricsEventPayload on this branch, not AnalyticsEvent. Keep metaMetricsController.trackEvent until platform-libs migrates deep-links/metrics.ts. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [68ae9e7]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 5 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Keep canTrackImmediately and addEventBeforeMetricsOptIn parity with main while migrating the immediate track path to trackAnalyticsEvent. Co-authored-by: Cursor <cursoragent@cursor.com>
Build the analytics event shape separately and pass environment and routing options only to trackAnalyticsEvent, matching main's split. Co-authored-by: Cursor <cursoragent@cursor.com>
Reuse built.options for trackAnalyticsEvent so delivery context is defined once when building the analytics event. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR continues the analytics migration by moving core platform/UI MetaMetrics event tracking off legacy metaMetricsController.trackEvent call sites and onto the new createEventBuilder + trackEvent/trackPage pathway (AnalyticsController-backed), including wiring for analytics page tracking.
Changes:
- Updated
MetaMetricsProviderto build analytics events viacreateEventBuilderand dispatch them usingtrackAnalyticsEvent. - Refactored background/controller tracking in
MetamaskControllerandbackground.jsto usecontrollers/analyticstrackEvent+createEventBuilder, and wiredtrackAnalyticsPage. - Updated unit tests to assert the new analytics event shape (
name+properties.category) and to mock the new tracking entrypoints.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/contexts/metametrics.tsx | Switches UI context event tracking to createEventBuilder + trackAnalyticsEvent. |
| ui/contexts/metametrics.test.tsx | Updates tests/mocks for the new analytics event format and dispatch function. |
| app/scripts/metamask-controller.js | Migrates controller-level background events and RPC hooks to trackEvent/trackPage + builder. |
| app/scripts/metamask-controller.test.js | Adjusts tests to mock controllers/analytics.trackEvent and validate new payload shape. |
| app/scripts/background.js | Migrates background event emission to trackEvent + createEventBuilder for key platform events. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Builds ready [c33568b]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 6 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Co-authored-by: Cursor <cursoragent@cursor.com>
…csEvent Guard optional payload.properties spreads in metamask-controller and update integration tests to assert trackAnalyticsEvent payload shape. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [f1ebc58]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 9 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
These Bridge controller methods were accidentally removed during the platform-bg analytics migration, breaking Bridge/Swap UI initialization and causing E2E timeouts. Co-authored-by: Cursor <cursoragent@cursor.com>
Extract trackOptions once and pass to both createEventBuilder.build and trackAnalyticsEvent, removing the unsafe built.options type assertion. Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid duplicating delivery options on builder.build() and trackAnalyticsEvent. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [669f507]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 10 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
@gauthierpetetin can approve again when merge conflict is resolved ~ |
Keep OnboardingCompleted event-name filter from platform-bg and use main's expect.objectContaining for analytics properties in integration tests. Co-authored-by: Cursor <cursoragent@cursor.com>
✨ Files requiring CODEOWNER review ✨🫰 @MetaMask/core-platform (1 files, +206 -97)
👨🔧 @MetaMask/extension-platform (1 files, +206 -97)
|
|
Builds ready [f0d51d2]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 5 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
Conflicts are resolved, it's ready to be re-approved! |


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: Merge before PR14. Includes
trackAnalyticsPageRPC wiring.Files in this PR: 11
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 many background and controller telemetry paths plus RPC shims; incorrect adapter mapping could drop or mis-shape events, though behavior is intended to be equivalent.
Overview
Migrates core platform MetaMetrics call sites from
metaMetricsController.trackEventtocreateEventBuilder+trackEvent(andtrackPagefor page views) viaapp/scripts/controllers/analytics, as part of the umbrella analytics migration (#43885).Background (
background.js,metamask-controller.js): Direct emissions (phishing, dapp viewed, port stream, app installed, SRP import, referrals, permissions, tx failure, etc.) now build events through the shared builder.trackMetaMetricsEvent,sendMetrics, and related RPC hooks remain for legacy{ event, category, properties }callers but forward through adapters that map into the builder before callingtrackEvent.trackAnalyticsPageis wired alongsidetrackMetaMetricsPage(both usetrackPage).UI (
metametrics.tsx): When metrics can be sent immediately, tracking goes throughtrackAnalyticsEventwith a builder-built payload instead oftrackMetaMetricsEvent.Tests are updated to mock/assert
trackEvent/trackAnalyticsEventand the new event shape (name,categoryunderpropertieswhere applicable).Reviewed by Cursor Bugbot for commit f0d51d2. Bugbot is set up for automated code reviews on this repo. Configure here.