Cherry-picking commits from main to release/7.67.0 for PR #26292#26316
Cherry-picking commits from main to release/7.67.0 for PR #26292#26316joaoloureirop merged 1 commit intorelease/7.67.0from
Conversation
## **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** ```gherkin 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** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!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). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 160d885. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
|
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. |
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - base branch is not main (base: release/7.67.0) All E2E tests pre-selected. |
| } | ||
|
|
||
| builtEvents.forEach((event) => MetaMetrics.getInstance().trackEvent(event)); | ||
| builtEvents.forEach((event) => analytics.trackEvent(event)); |
There was a problem hiding this comment.
saveDataRecording silently flipped from true to false
Medium Severity
Events tracked through withMetaMetrics now have saveDataRecording defaulting to false instead of true. The old path went through MetaMetrics.getInstance().trackEvent() which explicitly called .setSaveDataRecording(true). The new path calls analytics.trackEvent(event) directly, passing the event as-is from AnalyticsEventBuilder, which defaults saveDataRecording to false in createAnalyticsEvent. Unlike useAnalytics().trackEvent() — which overrides this to true via .setSaveDataRecording(saveDataRecording ?? true) — the direct analytics.trackEvent() call applies no such override. This affects GDPR data-recording compliance tracking for all events fired through withMetaMetrics.
Additional Locations (1)
|
|
No release label on PR. Adding release label release-7.67.0 on PR, as PR was cherry-picked in branch 7.67.0. |





Description
Phase 2 analytics migration (Batch 2-11): migrate Stake/Earn's
useMetricshook andMetaMetrics.getInstance()calls from the legacyMetaMetrics 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
useAnalyticsfromhooks/useAnalytics/useAnalyticsand importMetaMetricsEventsdirectly from
core/Analytics;withMetaMetricsutility now usesanalytics.trackEvent()andAnalyticsEventBuilderinstead ofMetaMetrics.getInstance().trackEvent()andMetricsEventBuilder; testmocks updated accordingly.
Changes
Source files (6):
LearnMoreModalFooter.tsx,StakingButtons.tsx,StakingBalance.tsx,StakeButton/index.tsx: replaceduseMetricswith
useAnalytics;MetaMetricsEventsnow imported fromcore/AnalyticsusePoolStakedDeposit/index.ts: replaceduseMetricswithuseAnalytics(also migrated as it's the source for a listed test file)withMetaMetrics.ts: replacedMetaMetrics.getInstance().trackEvent()withanalytics.trackEvent()and
MetricsEventBuilderwithAnalyticsEventBuilderTest files (3):
StakeButton.test.tsx: replaceduseMetricsmock withuseAnalyticsmock; added transitive
useMetricsmock for unmigrateduseStablecoinLendingRedirectdependency; replacedMetricsEventBuilderwithAnalyticsEventBuilderusePoolStakedDeposit.test.tsx: replaceduseMetricsmock/importwith
useAnalytics; replacedMetricsEventBuilderwithAnalyticsEventBuilderwithMetaMetrics.test.ts: replacedMetaMetrics.getInstance()spywith
analyticsmodule mock; updatedMetaMetricsEventsimport fromcore/AnalyticsChangelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-298 (Batch
2-11)
Manual testing steps
Screenshots/Recordings
N/A – analytics migration, no UI change.
Pre-merge author checklist
Docs and MetaMask Mobile
Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Note
Medium Risk
This is a broad analytics plumbing migration across Stake/Earn UI and transaction hooks; risk is mainly missed/changed event emission or metadata due to swapped builders and tracking surfaces, not user-facing flow changes.
Overview
Migrates Stake/Earn (Earn CTA, staking balance/buttons, learn-more modal, and pooled-stake deposit hook) from legacy
useMetrics/MetaMetrics.getInstance()tracking to the new analytics stack viauseAnalytics,analytics.trackEvent, andAnalyticsEventBuilder.Updates related unit tests to mock
useAnalytics/analyticsinstead ofuseMetrics/MetaMetrics, including a new mock foruseStablecoinLendingRedirectto avoid transitive legacy metrics behavior and keep navigation assertions stable.Written by Cursor Bugbot for commit 8971698. This will update automatically on new commits. Configure here.
b5b8c71