refactor(analytics): C4 migrate useMetrics to useAnalytics: Simulation + NFT + Hooks + Misc + perps#27885
Conversation
…ion + NFT + Hooks + Misc + perps Migrate ~18 files from useMetrics to useAnalytics hook. Rename addTraitsToUser → identify in ShowDisplayNFTMediaSheet. Update MetaMetricsEvents import paths to core/Analytics. Replace as-never mock casts with createMockUseAnalyticsHook.
|
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #27885 +/- ##
==========================================
+ Coverage 82.46% 82.52% +0.05%
==========================================
Files 4801 4798 -3
Lines 123807 123746 -61
Branches 27602 27573 -29
==========================================
+ Hits 102101 102116 +15
+ Misses 14634 14572 -62
+ Partials 7072 7058 -14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Notable functional change: In The Test files (DeepLinkModal.test.tsx, FeatureFlagOverride.test.tsx, NetworksManagementView.test.tsx, PerpsTransactionItem.test.tsx, etc.) are unit test updates to use the new mock pattern - these don't require E2E coverage but the underlying components they test do. The risk is medium because while the logic is preserved, the hook API migration could introduce subtle breakages in analytics tracking across these flows. The Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
|



Description
Part of the analytics migration workstream (#26686) that replaces the legacy
useMetricshook with the newuseAnalyticshook across the codebase.This PR (C4) migrates ~18 files covering Simulation Details, NFT display, Wallet Actions, hooks, and misc components, plus one perps test-only file.
Changes per file:
useMetricsimport/call withuseAnalyticsMetaMetricsEventsimport paths fromhooks/useMetrics→core/AnalyticsaddTraitsToUser→identifyinShowDisplayNFTMediaSheet(piggyback rename per workstream plan)createMockUseAnalyticsHook, usejest.mocked()instead ofas jest.Mock/as neverMetricsEventBuilderreferences toAnalyticsEventBuilderwhere applicableChangelog
CHANGELOG entry: null
Related issues
Fixes: #26815
Refs: #26686
Manual testing steps
N/A
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Mostly a mechanical analytics refactor, but it touches user flows (wallet reset, basic functionality, ramps, NFT detection, simulation confirmation) where incorrect hook behavior could change tracking/consent flags or event emission.
Overview
Migrates several components and hooks from legacy
useMetricsto the newuseAnalyticshook, keeping existing event tracking calls but updating imports/usages (e.g.,MetaMetricsEventspaths andAnalyticsEventBuilderin tests).Updates tests to mock
useAnalyticsviacreateMockUseAnalyticsHook/jest.mocked, and switches the NFT media consent sheet fromaddTraitsToUsertoidentifywhen recording user traits.Written by Cursor Bugbot for commit 59b8a7a. This will update automatically on new commits. Configure here.