Skip to content

refactor(analytics): D1 migrate Rewards from useMetrics to useAnalytics#28262

Merged
NicolasMassart merged 4 commits into
mainfrom
refactor/26686_d1-rewards_use-analytics-migration
Apr 8, 2026
Merged

refactor(analytics): D1 migrate Rewards from useMetrics to useAnalytics#28262
NicolasMassart merged 4 commits into
mainfrom
refactor/26686_d1-rewards_use-analytics-migration

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Important

Creates a dependency on D2 #28263 for createMockEventBuilder added in app/util/test/analyticsMock.ts.
if this PR has to be reverted, you also have to revert D2 #28263

Description

Part of #26686 (PR D1 — Rewards).

The useMetrics hook is deprecated in favour of useAnalytics, which integrates with the new AnalyticsController via the messenger pattern. This PR migrates all useMetrics usages in the Rewards module.

What changed:

  • Replaced useMetrics with useAnalytics across all Rewards components, views, and hooks (14 source files).
  • Updated MetaMetricsEvents imports to come directly from core/Analytics instead of the deprecated hooks/useMetrics re-export.
  • Updated all related test files to mock useAnalytics instead of useMetrics, using the createMockUseAnalyticsHook factory for consistency.
  • Added a createMockEventBuilder factory function to app/util/test/analyticsMock.ts to eliminate repeated inline event-builder mock boilerplate across test files.

Changelog

CHANGELOG entry: null

Related issues

Fixes: #26816
Refs: #26686

Manual testing steps

Feature: Rewards analytics events

  Scenario: user views the Rewards dashboard
    Given the user has opted into Rewards
    When user navigates to the Rewards dashboard
    Then the dashboard_viewed analytics event is tracked via useAnalytics

  Scenario: user views Rewards settings
    Given the user has opted into Rewards
    When user opens Rewards settings
    Then the settings_viewed analytics event is tracked via useAnalytics

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
Touches Rewards analytics/identify calls and event constant wiring; while behavior should be equivalent, mistakes could drop or mislabel telemetry and user-trait updates (opt-in/out, account-linking). Functional UI behavior is otherwise unchanged.

Overview
Migrates the Rewards module off deprecated useMetrics to useAnalytics, and switches MetaMetricsEvents imports to come directly from core/Analytics.

Updates Rewards hooks and screens to use identify in place of addTraitsToUser where traits are set (e.g., opt-in/out and opt-in summary), and refactors unit tests to mock useAnalytics consistently via shared factories.

Adds createMockEventBuilder to util/test/analyticsMock.ts to standardize event-builder mocks and reduce repeated inline test boilerplate.

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

Replace all useMetrics usages in the Rewards module with useAnalytics,
import MetaMetricsEvents from core/Analytics instead of hooks/useMetrics,
and add createMockEventBuilder factory to analyticsMock to eliminate
inline builder boilerplate across test files.
@NicolasMassart NicolasMassart self-assigned this Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

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 Apr 1, 2026
@github-actions github-actions Bot added the size-L label Apr 1, 2026
@github-project-automation github-project-automation Bot moved this to Needs dev review in PR review queue Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

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

@NicolasMassart NicolasMassart marked this pull request as ready for review April 1, 2026 16:47
@NicolasMassart NicolasMassart requested a review from a team as a code owner April 1, 2026 16:47
@github-actions github-actions Bot added the risk-low Low testing needed · Low bug introduction risk label Apr 1, 2026

@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.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread app/components/UI/Rewards/Views/RewardsDashboard.test.tsx Outdated
@NicolasMassart NicolasMassart enabled auto-merge April 2, 2026 08:24
@github-actions github-actions Bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 2, 2026
@github-actions github-actions Bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 2, 2026
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
All 34 changed files are confined to the app/components/UI/Rewards/ directory (plus one test utility file). The changes are a pure internal refactoring: replacing the useMetrics hook with useAnalytics hook across all Rewards components and hooks, renaming addTraitsToUser to identify, and cleaning up imports so MetaMetricsEvents comes directly from core/Analytics rather than via useMetrics. The analyticsMock.ts change only adds a new createMockEventBuilder helper function without modifying existing mocks. No behavioral changes are introduced - the same analytics events are tracked, just via a different hook. No E2E tests exist for the Rewards feature in the available test suite, and none of the available E2E test tags cover Rewards functionality. The changes do not touch any shared components (TabBar, Navigation, BottomSheets, Confirmations) that could break other test flows. This is a safe, isolated refactoring with no E2E test coverage needed.

Performance Test Selection:
The changes are a pure hook migration (useMetrics → useAnalytics) within the Rewards UI components. No performance-sensitive code paths are affected - no rendering logic, state management, list components, or critical user flows are changed. The refactoring only affects how analytics events are tracked, which has no measurable performance impact.

View GitHub Actions results

@sonarqubecloud

sonarqubecloud Bot commented Apr 2, 2026

Copy link
Copy Markdown

@NicolasMassart NicolasMassart added this pull request to the merge queue Apr 8, 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 Apr 8, 2026
Merged via the queue into main with commit a971982 Apr 8, 2026
63 checks passed
@NicolasMassart NicolasMassart deleted the refactor/26686_d1-rewards_use-analytics-migration branch April 8, 2026 12:57
@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 Apr 8, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 8, 2026
@weitingsun weitingsun added release-7.74.0 Issue or pull request that will be included in release 7.74.0 and removed release-7.78.0 labels Apr 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.74.0 Issue or pull request that will be included in release 7.74.0 risk-low Low testing needed · Low bug introduction risk size-L team-mobile-platform Mobile Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

PR D1: migrate useMetrics to useAnalytics in Rewards team (~21 files)

4 participants