Skip to content

refactor(analytics): migrate Batch 2-12: metamask-assets#26298

Merged
NicolasMassart merged 8 commits into
mainfrom
refactor/MCWP-297_analytics_migration_batch_2-12_metamask-assets
Feb 20, 2026
Merged

refactor(analytics): migrate Batch 2-12: metamask-assets#26298
NicolasMassart merged 8 commits into
mainfrom
refactor/MCWP-297_analytics_migration_batch_2-12_metamask-assets

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Description

Phase 2 analytics migration (Batch 2-12): migrate metamask-assets's asset components, token lists, collectible modals, DeFi positions, and token details from useMetrics/withMetricsAwareness to the new analytics system (useAnalytics/withAnalyticsAwareness).

Reason: Deprecate MetaMetrics in favour of the shared analytics utility and AnalyticsController.

Changes: 20 source files + 16 test files migrated. React components now use useAnalytics from app/components/hooks/useAnalytics/useAnalytics instead of useMetrics; class components use withAnalyticsAwareness instead of withMetricsAwareness (or removed the HOC when unused). MetaMetricsEvents imports moved from hooks/useMetrics to core/Analytics. Test mocks updated to mock useAnalytics instead of useMetrics.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-297 (Batch 2-12)

Manual testing steps

Feature: Assets analytics

  Scenario: user triggers an assets flow event
    Given app is open and user is in an assets flow

    When user performs an action that triggers analytics (e.g. add custom token, hide token, view NFT details, open token details)
    Then the event is tracked on Mixpanel

Screenshots/Recordings

N/A – analytics migration, no UI change.

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

Low Risk
Mostly mechanical analytics-hook/HOC and type import migrations with no functional UI or state-flow changes beyond event plumbing; risk is limited to missing/incorrect analytics injection causing lost tracking or test failures.

Overview
Migrates assets-related UI flows (custom token import, token list, asset/collectible detail modals, DeFi positions, and asset actions) from legacy useMetrics/withMetricsAwareness to the new analytics API (useAnalytics/withAnalyticsAwareness), updating call sites to use the new injected analytics prop/hook methods.

Updates supporting utilities (goToAddEvmToken, removeEvmToken) to use AnalyticsEventBuilder types and moves MetaMetricsEvents imports to core/Analytics. Adjusts a large set of unit tests to mock useAnalytics instead of useMetrics, and removes the metrics HOC wrapper from Views/Asset where it’s no longer needed.

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

@NicolasMassart NicolasMassart self-assigned this Feb 19, 2026
@NicolasMassart NicolasMassart added the team-mobile-platform Mobile Platform team label Feb 19, 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.

NicolasMassart and others added 5 commits February 19, 2026 22:10
…sk-assets' of github.com:MetaMask/metamask-mobile into refactor/MCWP-297_analytics_migration_batch_2-12_metamask-assets
…sk-assets' of github.com:MetaMask/metamask-mobile into refactor/MCWP-297_analytics_migration_batch_2-12_metamask-assets
@NicolasMassart NicolasMassart marked this pull request as ready for review February 19, 2026 22:15
@NicolasMassart NicolasMassart requested a review from a team as a code owner February 19, 2026 22:15
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeWalletPlatform
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR is a pure refactoring change that migrates from useMetrics hook to a new useAnalytics hook across 37 files. The changes are:

  1. Import path changes: useMetricsuseAnalytics from a new path
  2. Type updates: MetricsEventBuilderAnalyticsEventBuilder, ITrackingEventAnalyticsTrackingEvent
  3. HOC migration: withMetricsAwarenesswithAnalyticsAwareness
  4. Method rename: getMetaMetricsIdgetAnalyticsId

The new useAnalytics hook maintains the same API interface as useMetrics, providing identical methods (trackEvent, createEventBuilder, addTraitsToUser, enable, etc.). This is a drop-in replacement with no functional changes to the UI components.

Affected components include:

  • Token list and token items (TokenList, TokenListItem, TokenListItemV2)
  • Asset overview and details screens
  • NFT/Collectible modals and detection
  • DeFi positions display
  • Custom token addition and removal utilities

Since this is a refactoring that doesn't change any business logic or UI behavior, the risk is low. However, selecting SmokeWalletPlatform provides coverage for:

  • Token display and interactions (transaction history, token lists)
  • Wallet lifecycle analytics tracking
  • Core wallet platform features

This tag covers the main areas affected by the analytics hook migration without over-testing for what is essentially a code organization change. All unit tests have been updated to mock the new hook, indicating the changes are well-tested at the unit level.

Performance Test Selection:
This PR is a pure refactoring change that migrates from useMetrics to useAnalytics hook. The changes are limited to import paths, type definitions, and hook names - no functional changes to rendering, data loading, or state management. The useAnalytics hook provides the same API interface as useMetrics, so there should be no performance impact. No performance tests are needed for this analytics infrastructure refactoring.

View GitHub Actions results

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

import DeFiPositionsListItem from './DeFiPositionsListItem';
import { backgroundState } from '../../../util/test/initial-root-state';
import { MetaMetricsEvents } from '../../hooks/useMetrics';
import { MetaMetricsEvents } from '../../../core/Analytics';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test still uses deprecated MetricsEventBuilder instead of AnalyticsEventBuilder

Low Severity

This is the only test file in the migrated batch that still imports and uses MetricsEventBuilder from ../../../core/Analytics/MetricsEventBuilder — both in the mock factory (line 21–27) and in the test assertion (line 186). Every other migrated test file in this PR either uses AnalyticsEventBuilder or pure jest.fn() mocks. This creates an unnecessary dependency on the deprecated module in a file that's otherwise fully migrated to the new analytics system.

Additional Locations (1)

Fix in Cursor Fix in Web

@sonarqubecloud

Copy link
Copy Markdown

@NicolasMassart NicolasMassart added this pull request to the merge queue Feb 20, 2026
@github-project-automation github-project-automation Bot moved this from Needs dev review to Review finalised - Ready to be merged in PR review queue Feb 20, 2026
Merged via the queue into main with commit 78dd80e Feb 20, 2026
97 checks passed
@NicolasMassart NicolasMassart deleted the refactor/MCWP-297_analytics_migration_batch_2-12_metamask-assets branch February 20, 2026 10:14
@github-project-automation github-project-automation Bot moved this from Review finalised - Ready to be merged to Merged, Closed or Archived in PR review queue Feb 20, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 20, 2026
@metamaskbot metamaskbot added the release-7.68.0 Issue or pull request that will be included in release 7.68.0 label Feb 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.68.0 Issue or pull request that will be included in release 7.68.0 size-M team-mobile-platform Mobile Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants