Skip to content

refactor(analytics): C4 migrate useMetrics to useAnalytics: Simulation + NFT + Hooks + Misc + perps#27885

Merged
NicolasMassart merged 4 commits into
mainfrom
refactor/26686_c4_gas-sim-nft-hooks-misc
Mar 26, 2026
Merged

refactor(analytics): C4 migrate useMetrics to useAnalytics: Simulation + NFT + Hooks + Misc + perps#27885
NicolasMassart merged 4 commits into
mainfrom
refactor/26686_c4_gas-sim-nft-hooks-misc

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Description

Part of the analytics migration workstream (#26686) that replaces the legacy useMetrics hook with the new useAnalytics hook 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:

  • Replace useMetrics import/call with useAnalytics
  • Update MetaMetricsEvents import paths from hooks/useMetricscore/Analytics
  • Rename addTraitsToUseridentify in ShowDisplayNFTMediaSheet (piggyback rename per workstream plan)
  • In tests: replace hand-rolled mock objects with createMockUseAnalyticsHook, use jest.mocked() instead of as jest.Mock / as never
  • Update MetricsEventBuilder references to AnalyticsEventBuilder where applicable

Changelog

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

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

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 useMetrics to the new useAnalytics hook, keeping existing event tracking calls but updating imports/usages (e.g., MetaMetricsEvents paths and AnalyticsEventBuilder in tests).

Updates tests to mock useAnalytics via createMockUseAnalyticsHook/jest.mocked, and switches the NFT media consent sheet from addTraitsToUser to identify when recording user traits.

Written by Cursor Bugbot for commit 59b8a7a. This will update automatically on new commits. Configure here.

…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.
@NicolasMassart NicolasMassart self-assigned this Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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.

@metamaskbot metamaskbot added the team-mobile-platform Mobile Platform team label Mar 24, 2026
@github-project-automation github-project-automation Bot moved this to Needs dev review in PR review queue Mar 24, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.52%. Comparing base (c56e9d0) to head (46f421d).
⚠️ Report is 45 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@NicolasMassart NicolasMassart marked this pull request as ready for review March 25, 2026 10:08
@NicolasMassart NicolasMassart requested a review from a team as a code owner March 25, 2026 10:08
@github-actions github-actions Bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Mar 25, 2026
@NicolasMassart NicolasMassart changed the title refactor(analytics): PR C4 migrate useMetrics to useAnalytics: Simulation + NFT + Hooks + Misc + perps refactor(analytics): C4 migrate useMetrics to useAnalytics: Simulation + NFT + Hooks + Misc + perps Mar 25, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeConfirmations, SmokeRamps, SmokeWalletPlatform, SmokeIdentity, SmokeAccounts
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 82%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 18 changed files are part of a migration from the deprecated useMetrics hook to the new useAnalytics hook. This is a refactoring effort, but it touches analytics tracking across multiple critical user flows:

  1. SmokeConfirmations: useSimulationMetrics.ts migrated to useAnalytics - this directly affects transaction simulation metrics tracking in the confirmations flow. Any breakage here could affect how simulation events are tracked during transaction confirmations.

  2. SmokeRamps: FundActionMenu.tsx migrated to useAnalytics - this is the entry point for buy/sell (ramp) flows. Analytics events for ramp actions need to be verified.

  3. SmokeWalletPlatform: useBuildPortfolioUrl.ts migrated (portfolio URL building with analytics consent check), DeleteWalletModal migrated, BasicFunctionalityModal migrated. These are core wallet platform features.

  4. SmokeIdentity: usePromptSeedlessRelogin.ts migrated - this is directly related to seedless/identity flows and re-login prompts.

  5. SmokeAccounts: DeleteWalletModal migration affects wallet deletion flow which is account management. Also usePromptSeedlessRelogin relates to account/identity management.

Notable functional change: In ShowDisplayNFTMediaSheet.tsx, addTraitsToUser(traits) was renamed to identify(traits) - this is an API method rename that could affect user trait tracking for NFT media settings.

The useNftDetection.ts migration also affects NFT detection analytics, but NFT detection doesn't have a dedicated E2E tag - it's covered under SmokeWalletPlatform.

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 identify rename is a functional change that needs verification.

Performance Test Selection:
The changes are purely a hook migration from useMetrics to useAnalytics - an analytics/tracking refactor. There are no changes to UI rendering, data loading, state management, list components, or app initialization that would impact performance metrics. No performance tests are needed.

View GitHub Actions results

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
18 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@github-project-automation github-project-automation Bot moved this from Needs dev review to Review finalised - Ready to be merged in PR review queue Mar 26, 2026
@NicolasMassart NicolasMassart added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit 5e7b624 Mar 26, 2026
102 checks passed
@NicolasMassart NicolasMassart deleted the refactor/26686_c4_gas-sim-nft-hooks-misc branch March 26, 2026 14:53
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-mobile-platform Mobile Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

PR C4: migrate useMetrics to useAnalytics in Gas, Simulation, NFT, Hooks, Misc, perps (~20 files)

4 participants