refactor(analytics): migrate assets events - #43889
Conversation
✨ Files requiring CODEOWNER review ✨💎 @MetaMask/metamask-assets (9 files, +245 -187)
|
Builds ready [76c2703]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs
|
76c2703 to
e5af2af
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 [e5af2af]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs
|
e5af2af to
5de1323
Compare
5de1323 to
f43ba02
Compare
f43ba02 to
ef96a09
Compare
ef96a09 to
58284a6
Compare
58284a6 to
29ab1bc
Compare
Builds ready [29ab1bc] [reused from f43ba02]
⚡ Performance Benchmarks (Total: 🟢 0 pass · 🟡 0 warn · 🔴 0 fail)
Bundle size diffs: data not available. |
29ab1bc to
cf7701b
Compare
cf7701b to
bdbe2d1
Compare
There was a problem hiding this comment.
Pull request overview
This PR is a mechanical refactor within the assets domain to migrate legacy MetaMetrics trackEvent usage to the new analytics event builder pattern (createEventBuilder(...).addCategory(...).addProperties/...build()) via useAnalytics() in the UI and app/scripts/controllers/analytics in the background.
Changes:
- Updated multiple UI assets components to build analytics events via
useAnalytics()instead ofMetaMetricsContext. - Updated associated unit tests to mock
useAnalytics()and assert against the built event shape (name,properties.category,sensitiveProperties). - Updated NFT controller initialization to emit
NftAddedviacontrollers/analyticsand removed the init-messenger delegation forMetaMetricsController:trackEvent.
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 |
|---|---|
| ui/pages/asset/components/token-buttons.tsx | Migrates token button click analytics to useAnalytics() + event builder. |
| ui/pages/asset/components/token-asset.tsx | Migrates block-explorer click analytics to useAnalytics() + event builder. |
| ui/pages/asset/components/native-asset.tsx | Migrates native-asset block-explorer click analytics to useAnalytics() + event builder. |
| ui/pages/asset/components/musd-bonus-section.tsx | Migrates mUSD bonus CTA/click analytics to event builder. |
| ui/pages/asset/components/musd-bonus-section.test.tsx | Updates tests to mock useAnalytics() and assert new built event shape. |
| ui/pages/asset/components/asset-page.test.tsx | Adds useAnalytics() mock to support updated child instrumentation. |
| ui/pages/asset/components/asset-options.js | Migrates token hide analytics to event builder with sensitive properties. |
| ui/components/app/assets/token-list/token-list.tsx | Migrates token list click/toggle analytics to event builder. |
| ui/components/app/assets/token-list/token-list.test.tsx | Updates token list tests to mock useAnalytics() and assert built event shape. |
| ui/components/app/assets/nfts/nft-empty-state/nft-empty-state.tsx | Migrates empty-state import CTA analytics to event builder. |
| ui/components/app/assets/nfts/nft-details/nft-details.tsx | Migrates NFT details opened analytics to event builder. |
| ui/components/app/assets/defi-list/cells/defi-empty-state.tsx | Migrates DeFi empty-state CTA analytics to event builder. |
| ui/components/app/assets/asset-list/sort-control/sort-control.tsx | Migrates sort preference analytics to event builder. |
| ui/components/app/assets/asset-list/sort-control/sort-control.test.tsx | Updates sort-control test to mock useAnalytics() and assert built event shape. |
| ui/components/app/assets/asset-list/asset-list.tsx | Migrates token screen opened analytics to event builder and fixes hook deps. |
| ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx | Migrates import/management analytics to event builder. |
| app/scripts/messenger-client-init/messengers/assets/nft-controller-messenger.ts | Removes init messenger delegation for legacy MetaMetricsController:trackEvent. |
| app/scripts/messenger-client-init/assets/nft-controller-init.ts | Emits NftAdded via controllers/analytics event builder + trackEvent. |
Comments suppressed due to low confidence (1)
ui/components/app/assets/asset-list/sort-control/sort-control.test.tsx:65
SortControlusesuseSelector(getTokenSortConfig), but this mock checksselector === getPreferences, so it never returns the intended sort config. Update the mock to key offgetTokenSortConfigso the test reflects real selector usage.
(useSelector as jest.Mock).mockImplementation((selector) => {
if (selector === getPreferences) {
return {
key: 'tokenFiatAmount',
sortCallback: 'stringNumeric',
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Builds ready [961a6a2]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Fix useSelector mock to match SortControl selector usage so sort config selection state is exercised in unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [756ae4b]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Fix Test lint CI failure on the assets analytics migration PR. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Builds ready [df2adfb]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 11 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 after PR1.
Files in this PR: 25
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
Mechanical analytics API refactor with no product logic changes; tests updated to match the new event object shape.
Overview
Migrates assets MetaMetrics call sites from legacy
trackEvent({ event, category, properties })/ messengerMetaMetricsController:trackEventtocreateEventBuilder+trackEventviauseAnalytics()in UI andapp/scripts/controllers/analyticsin the background.UI touches token/NFT/DeFi lists, sort/import controls, asset pages (hide token, block explorer, buy/send), and mUSD bonus CTAs—event names and payloads stay the same; only the wiring changes.
Background:
NftControlleronNftAddedno longer uses the init messenger for metrics; NFT init messenger dropsMetaMetricsController:trackEventdelegation.Tests mock
useAnalyticsand assert the built event shape (name,properties.category,sensitiveProperties).Reviewed by Cursor Bugbot for commit df2adfb. Bugbot is set up for automated code reviews on this repo. Configure here.