refactor(analytics): migrate earn/mUSD events#43888
Conversation
|
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. |
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/earn (14 files, +239 -299)
💎 @MetaMask/metamask-assets (1 files, +17 -16)
|
Builds ready [07ff9bd]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs
|
07ff9bd to
7a7f4dc
Compare
Builds ready [7a7f4dc]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs
|
7a7f4dc to
bff443b
Compare
bff443b to
81894c0
Compare
81894c0 to
9a50f22
Compare
9a50f22 to
b83bad8
Compare
b83bad8 to
b5c9d4b
Compare
b5c9d4b to
5dae18f
Compare
5dae18f to
3be9b7a
Compare
3be9b7a to
df61d09
Compare
Builds ready [d3cf6ff] [reused from 87113f4]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs
|
Limit scope to domain bucket files only. Part of analytics migration umbrella PR #43885.
d3cf6ff to
ef3a7b5
Compare
Builds ready [ef3a7b5]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs
|
Drop the unused analytics integration helper and the redundant init-layer trackEvent unit test. DeFi analytics coverage remains in the integration test. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates Earn/mUSD (and related DeFi positions) UI/background analytics call sites from legacy MetaMetricsContext / trackMetaMetricsEvent payloads to the newer useAnalytics() + createEventBuilder() / trackAnalyticsEvent pathway, aligning with the broader AnalyticsController migration tracked in #43885.
Changes:
- Updated mUSD UI screens/components and hooks to build analytics events via
createEventBuilder(...).addCategory(...).addProperties(...).build()and send them throughuseAnalytics().trackEvent. - Updated DeFi positions UI analytics and background controller init wiring to route through
app/scripts/controllers/analytics. - Updated integration/unit tests to assert against the new event shape (
name,properties.category, etc.) and new RPC method (trackAnalyticsEvent).
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| app/scripts/messenger-client-init/defi-positions/defi-positions-controller-init.test.ts | Adds coverage that the DeFi positions controller’s trackEvent is routed through the analytics controller layer. |
| app/scripts/messenger-client-init/defi-positions/defi-positions-controller-init.ts | Replaces MetaMetrics controller delegation with direct createEventBuilder + trackEvent (analytics controller) mapping for DeFi positions. |
| app/scripts/messenger-client-init/messengers/defi-positions/defi-positions-controller-messenger.ts | Removes MetaMetrics controller track action delegation from the DeFi positions init messenger. |
| test/integration/defi/defi-positions.test.tsx | Updates integration assertions to the new RPC method (trackAnalyticsEvent) and event shape (name, options). |
| test/integration/helpers/analytics-integration-helpers.ts | Adds helper utilities for inspecting trackAnalyticsEvent background RPC calls in integration tests. |
| ui/components/app/assets/defi-list/cells/defi-protocol-cell.tsx | Migrates DeFi “details opened” tracking from MetaMetricsContext to useAnalytics + event builder. |
| ui/components/app/musd/claim-bonus-badge.test.tsx | Updates unit tests to mock useAnalytics and assert the new built event payload shape. |
| ui/components/app/musd/claim-bonus-badge.tsx | Migrates claim-bonus badge impression/click analytics to useAnalytics + event builder. |
| ui/components/app/musd/musd-asset-cta.test.tsx | Updates mUSD asset CTA tests to mock useAnalytics instead of MetaMetrics context. |
| ui/components/app/musd/musd-asset-cta.tsx | Migrates mUSD asset CTA click analytics to the event builder API. |
| ui/components/app/musd/musd-buy-get-cta.test.tsx | Updates buy/get CTA tests for the new analytics hook + event builder. |
| ui/components/app/musd/musd-buy-get-cta.tsx | Migrates buy/get CTA click analytics to the event builder API. |
| ui/components/app/musd/musd-convert-link.test.tsx | Updates convert link tests to mock useAnalytics and assert category under properties. |
| ui/components/app/musd/musd-convert-link.tsx | Migrates convert-link CTA click analytics to useAnalytics + event builder. |
| ui/hooks/musd/useMerklClaimStatus.test.ts | Updates Merkl claim hook tests to mock useAnalytics instead of MetaMetrics context. |
| ui/hooks/musd/useMerklClaimStatus.ts | Migrates Merkl claim status analytics to event builder + useAnalytics. |
| ui/hooks/musd/useMusdConversionToastStatus.test.ts | Updates conversion toast hook tests to mock useAnalytics and new event shape. |
| ui/hooks/musd/useMusdConversionToastStatus.ts | Migrates conversion status toast analytics to event builder + useAnalytics. |
| ui/pages/musd/screens/education.test.tsx | Updates education screen tests to mock useAnalytics and assert name-based events. |
| ui/pages/musd/screens/education.tsx | Migrates education screen display/click analytics to useAnalytics + event builder. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Builds ready [d716d33]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|


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.
Files in this PR: 26
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
Low Risk
Analytics-only refactor with no change to conversion, claim, or DeFi product logic; risk is mainly telemetry shape/pipeline regressions, covered by updated unit and integration tests.
Overview
This PR moves earn / mUSD and related DeFi analytics off legacy
MetaMetricsContext/MetaMetricsController:trackEventonto the sharedcreateEventBuilder+trackEventpath (useAnalyticsin UI,app/scripts/controllers/analyticsin background).UI: mUSD CTAs, claim badge, convert links, education screen, and transaction-status hooks now build events with the builder (
name, category inproperties, optionalsensitiveProperties) instead of flat{ event, category, properties }payloads.Background:
DeFiPositionsControllergets a localtrackEventadapter that maps legacy controller payloads into built analytics events; the init messenger no longer delegatesMetaMetricsController:trackEvent.Tests: mocks switch from
metametricscontext touseAnalytics; integration DeFi tests asserttrackAnalyticsEventand the new event/options shape.Reviewed by Cursor Bugbot for commit d716d33. Bugbot is set up for automated code reviews on this repo. Configure here.