Skip to content

refactor(analytics): migrate Batch 2-11: metamask-earn#26292

Merged
NicolasMassart merged 7 commits into
mainfrom
refactor/MCWP-298_analytics_migration_batch_2-11_metamask-earn
Feb 20, 2026
Merged

refactor(analytics): migrate Batch 2-11: metamask-earn#26292
NicolasMassart merged 7 commits into
mainfrom
refactor/MCWP-298_analytics_migration_batch_2-11_metamask-earn

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Description

Phase 2 analytics migration (Batch 2-11): migrate Stake/Earn's useMetrics hook and MetaMetrics.getInstance() calls from the legacy MetaMetrics system to the new analytics system.

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

Changes: Stake components and hooks now use useAnalytics from hooks/useAnalytics/useAnalytics and import MetaMetricsEvents directly from core/Analytics; withMetaMetrics utility now uses analytics.trackEvent() and AnalyticsEventBuilder instead of MetaMetrics.getInstance().trackEvent() and MetricsEventBuilder; test mocks updated accordingly.

Changes

Source files (6):

  • LearnMoreModalFooter.tsx, StakingButtons.tsx, StakingBalance.tsx, StakeButton/index.tsx: replaced useMetrics with useAnalytics; MetaMetricsEvents now imported from core/Analytics
  • usePoolStakedDeposit/index.ts: replaced useMetrics with useAnalytics (also migrated as it's the source for a listed test file)
  • withMetaMetrics.ts: replaced MetaMetrics.getInstance().trackEvent() with analytics.trackEvent() and MetricsEventBuilder with AnalyticsEventBuilder

Test files (3):

  • StakeButton.test.tsx: replaced useMetrics mock with useAnalytics mock; added transitive useMetrics mock for unmigrated useStablecoinLendingRedirect dependency; replaced MetricsEventBuilder with AnalyticsEventBuilder
  • usePoolStakedDeposit.test.tsx: replaced useMetrics mock/import with useAnalytics; replaced MetricsEventBuilder with AnalyticsEventBuilder
  • withMetaMetrics.test.ts: replaced MetaMetrics.getInstance() spy with analytics module mock; updated MetaMetricsEvents import from core/Analytics

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-298 (Batch 2-11)

Manual testing steps

Feature: Stake/Earn analytics

  Scenario: user triggers a stake/earn flow event
    Given app is open and user is in a stake/earn flow

    When user performs an action that triggers analytics (e.g. stake button, unstake button, learn more, view staked positions)
    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

Medium Risk
Touches analytics instrumentation across multiple stake/earn entry points and a shared withMetaMetrics wrapper, so incorrect wiring could silently drop or duplicate events; functional app behavior should be unchanged.

Overview
Updates Stake/Earn UI components and staking hooks to use the new analytics stack by replacing legacy useMetrics/MetricsEventBuilder and MetaMetrics.getInstance().trackEvent() calls with useAnalytics, AnalyticsEventBuilder, and analytics.trackEvent(), while importing MetaMetricsEvents from core/Analytics.

Refactors withMetaMetrics to build events with the new builder and dispatch via the shared analytics utility (including promise-handling), and updates affected unit tests/mocks accordingly (including a useStablecoinLendingRedirect mock to keep navigation tests stable).

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

Updated components and hooks to replace the useMetrics hook with useAnalytics, ensuring consistent analytics tracking across the application. This change includes modifications to LearnMoreModalFooter, StakeButton, StakingBalance, and related test files to utilize the new analytics structure. Additionally, adjusted event tracking methods to align with the new analytics implementation.
Refactored the StakeButton test file to replace the previous useMetrics mock with a new mock for useStablecoinLendingRedirect. This change ensures that the tests accurately reflect the current analytics structure and improve the clarity of the test setup.
@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 NicolasMassart moved this to Needs dev review in PR review queue Feb 19, 2026
@NicolasMassart NicolasMassart marked this pull request as ready for review February 19, 2026 21:22
@NicolasMassart NicolasMassart requested a review from a team as a code owner February 19, 2026 21:22

@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 2 potential issues.

Comment thread app/components/UI/Stake/utils/metaMetrics/withMetaMetrics.ts
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
This PR is a pure refactoring change that migrates analytics tracking in Stake components from the useMetrics hook to a new useAnalytics hook. The changes include:

  1. Replacing useMetrics with useAnalytics hook imports
  2. Replacing MetricsEventBuilder with AnalyticsEventBuilder
  3. Replacing MetaMetrics.getInstance().trackEvent() with analytics.trackEvent()

The useAnalytics hook provides the same API as useMetrics (trackEvent, createEventBuilder, enable, addTraitsToUser, etc.), so this is a drop-in replacement that doesn't change any functional behavior.

The affected components are:

  • LearnMoreModalFooter (staking learn more modal)
  • StakeButton (stake button component)
  • StakingBalance (balance display)
  • StakingButtons (action buttons)
  • usePoolStakedDeposit hook
  • withMetaMetrics utility

Since staking flows are mentioned in the SmokeTrade tag description ("native ETH staking flows initiated from the wallet actions menu"), I'm selecting SmokeTrade as a precautionary measure. However, the risk is low because:

  1. This is purely an analytics implementation change, not a functional change
  2. The new hook provides the same API as the old one
  3. All unit tests have been updated to mock the new hook
  4. No user-facing behavior should change

Performance Test Selection:
This PR only changes analytics tracking implementation in Stake components, migrating from useMetrics to useAnalytics hook. The changes are purely internal refactoring of how analytics events are tracked and do not affect UI rendering, data loading, state management, or any performance-critical paths. No performance tests are needed.

View GitHub Actions results

@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 19, 2026
@sonarqubecloud

Copy link
Copy Markdown

@NicolasMassart NicolasMassart added this pull request to the merge queue Feb 20, 2026
Merged via the queue into main with commit b5b8c71 Feb 20, 2026
88 checks passed
@NicolasMassart NicolasMassart deleted the refactor/MCWP-298_analytics_migration_batch_2-11_metamask-earn branch February 20, 2026 00:40
@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 release-7.68.0 Issue or pull request that will be included in release 7.68.0 release-7.67.0 Issue or pull request that will be included in release 7.67.0 and removed release-7.68.0 Issue or pull request that will be included in release 7.68.0 labels Feb 20, 2026
@metamaskbot

Copy link
Copy Markdown
Collaborator

Missing release label release-7.67.0 on PR. Adding release label release-7.67.0 on PR and removing other release labels(release-7.68.0), as PR was cherry-picked in branch 7.67.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.67.0 Issue or pull request that will be included in release 7.67.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