Skip to content

refactor: E5 migrate MetricsEventBuilder to AnalyticsEventBuilder in onboarding components#31019

Merged
NicolasMassart merged 4 commits into
mainfrom
refactor/26686_e5-platform_migrate-event-builder
Jun 10, 2026
Merged

refactor: E5 migrate MetricsEventBuilder to AnalyticsEventBuilder in onboarding components#31019
NicolasMassart merged 4 commits into
mainfrom
refactor/26686_e5-platform_migrate-event-builder

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

Migrates onboarding-related components from the legacy MetricsEventBuilder (located in app/core/Analytics/) to the new AnalyticsEventBuilder (located in app/util/analytics/), as part of the broader useMetricsuseAnalytics analytics migration.

Changes:

  • Replaces all MetricsEventBuilder.createEventBuilder calls with AnalyticsEventBuilder.createEventBuilder in DeleteWalletModal, AccountStatus, backupUtils, and their tests
  • Converts imperative builder style in backupUtils to the fluent chain pattern consistent with the rest of the codebase
  • Removes no-op .setSaveDataRecording(true) calls from the migrated components (the method is a compatibility shim pending full removal in a follow-up PR)
  • Updates app/core/Analytics/README.md to point to AnalyticsEventBuilder as the canonical builder and marks MetricsEventBuilder as legacy
  • Updates test mocks to use jest.mocked() instead of as jest.Mock type assertions

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/MOBILE-26686

Manual testing steps

Feature: Onboarding analytics events

  Scenario: user deletes wallet
    Given the user has an existing wallet
    And MetaMetrics is enabled
    When user navigates to Settings > Security & Privacy > Delete wallet
    And confirms deletion
    Then the app returns to the onboarding screen without crashing
    And the "Reset Wallet Confirmed" event appears in Segment/Mixpanel
      with no missing or unexpected properties

  Scenario: user goes through SRP picker flow
    Given the user is on the SRP list screen
    And MetaMetrics is enabled
    When user taps an SRP entry
    Then navigation proceeds as expected
    And the "Secret Recovery Phrase Picker Clicked" event appears in Segment/Mixpanel
      with the expected properties (e.g. keyring_id)

  Scenario: user is on the AccountStatus screen (social login)
    Given the user went through social login and landed on AccountStatus
    And MetaMetrics is enabled
    When the screen mounts
    Then either "Account Already Exists Page Viewed" or "Account Not Found Page Viewed"
      appears in Segment/Mixpanel with the expected account_type property

Screenshots/Recordings

Before

N/A — refactor only, no UI changes

After

N/A — refactor only, no UI changes

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

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
Mechanical import and builder-style refactor with README and test updates only; no auth, data, or UI logic changes in the diff.

Overview
Continues the useMetrics → useAnalytics migration by standardizing on AnalyticsEventBuilder (app/util/analytics/) instead of the legacy MetricsEventBuilder under app/core/Analytics/.

backupUtils now builds onboarding tracking events with a single fluent chain (createEventBuilderaddPropertiesbuild) before trackOnboarding, matching the pattern used elsewhere. actionButtonTracking.test.ts mocks and imports AnalyticsEventBuilder from the util path and uses jest.mocked() for typings. app/core/Analytics/README.md names AnalyticsEventBuilder as the canonical builder, marks MetricsEventBuilder as legacy, and updates legacy HOC examples to import from @/util/analytics/AnalyticsEventBuilder.

No user-facing behavior change; event names and properties should stay the same for the touched onboarding/analytics call sites.

Reviewed by Cursor Bugbot for commit bdd28c8. Bugbot is set up for automated code reviews on this repo. Configure here.

…oarding components

Replace legacy MetricsEventBuilder with AnalyticsEventBuilder across onboarding-related
components and their tests, and clean up no-op setSaveDataRecording calls.
@NicolasMassart NicolasMassart self-assigned this Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 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.

@github-actions github-actions Bot added the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label Jun 3, 2026
@mm-token-exchange-service mm-token-exchange-service Bot added the team-mobile-platform Mobile Platform team label Jun 3, 2026
@github-actions github-actions Bot added the size-S label Jun 3, 2026
@NicolasMassart NicolasMassart marked this pull request as ready for review June 3, 2026 15:52
@NicolasMassart NicolasMassart requested a review from a team as a code owner June 3, 2026 15:52
@NicolasMassart NicolasMassart moved this to Needs dev review in PR review queue Jun 3, 2026
@github-actions github-actions Bot added the risk:medium AI analysis: medium risk label Jun 3, 2026
@NicolasMassart NicolasMassart changed the title refactor: migrate MetricsEventBuilder to AnalyticsEventBuilder in onboarding components refactor: E5 migrate MetricsEventBuilder to AnalyticsEventBuilder in onboarding components Jun 3, 2026
pull Bot pushed a commit to Dustin4444/metamask-mobile that referenced this pull request Jun 9, 2026
…lder→AnalyticsEventBuilder (assets files) (MetaMask#31251)

## **Description**

Migrates assets-related test files from the legacy analytics system
(`useMetrics`, `MetricsEventBuilder`, `addTraitsToUser`) to the new
system (`useAnalytics`, `AnalyticsEventBuilder`, `identify`).

Part of the analytics migration cleanup series. All changes are in files
owned by the assets team.

Files migrated: `DeFiPositionsListItem.test.tsx`, `TokenList.test.tsx`,
`TokenListItem.test.tsx`, `NftDetails.test.ts`.

Note: `TokenListItem.test.tsx` has a pre-existing test failure on `main`
unrelated to this change (tracked by MetaMask#31019).

## **Changelog**

CHANGELOG entry: null

## **Related issues**

Refs: MetaMask#26686

## **Manual testing steps**

N/A — analytics-only refactor, no behaviour change.

## **Screenshots/Recordings**

### **Before**

N/A

### **After**

N/A

## **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.

#### Performance checks (if applicable)

- [x] I've tested on Android
- [x] I've tested with a power user scenario
- [x] I've instrumented key operations with Sentry traces for production
performance metrics

## **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.

<!-- Generated with the help of the pr-description AI skill -->

Made with [Cursor](https://cursor.com)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Changes are limited to test mocks and import paths; runtime
wallet/assets behavior is unchanged.
> 
> **Overview**
> Updates **assets-team unit tests** so mocks and assertions match the
new analytics API—no production code changes.
> 
> **DeFi / token list tests** swap `MetricsEventBuilder` for
`AnalyticsEventBuilder` (imports and `jest.requireActual` paths under
`util/analytics`). DeFi navigation analytics expectations now build
events with `AnalyticsEventBuilder.createEventBuilder`.
> 
> **TokenList.test.tsx** extends the `useAnalytics` mock with `identify`
and a default `isDataRecorded` implementation so it mirrors the current
hook surface.
> 
> **TokenListItem.test.tsx** loads `MetaMetricsEvents` from
`core/Analytics` instead of the legacy `useMetrics` path for mUSD CTA
event assertions.
> 
> **NftDetails.test.ts** aligns the `useAnalytics` mock with the new API
(`identify`; drops unused legacy mock fields like `addTraitsToUser` /
`isDataRecorded` where no longer needed).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
e33ebdf. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
andrepimenta
andrepimenta previously approved these changes Jun 9, 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 Jun 9, 2026
@NicolasMassart NicolasMassart enabled auto-merge June 9, 2026 16:56
@github-actions github-actions Bot added risk:low AI analysis: low risk and removed risk:medium AI analysis: medium risk labels Jun 9, 2026
@NicolasMassart NicolasMassart removed the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label Jun 10, 2026
@github-actions

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: 97%
click to see 🤖 AI reasoning details

E2E Test Selection:
All three changed files are low-risk with no functional impact on E2E test flows:

  1. app/core/Analytics/README.md: Pure documentation update renaming MetricsEventBuilder to AnalyticsEventBuilder in text/code examples. No code changes.

  2. app/util/analytics/actionButtonTracking.test.ts: Unit test refactor updating mock references from MetricsEventBuilder to AnalyticsEventBuilder. This is a test-only file with no impact on app behavior or E2E flows.

  3. app/util/onboarding/backupUtils.ts: Cosmetic refactor converting sequential variable assignment to method chaining (AnalyticsEventBuilder.createEventBuilder(event).addProperties(properties).build()). The logic is functionally identical - same methods called in the same order, just without an intermediate variable. No behavioral change to onboarding analytics tracking.

None of these changes affect user-facing functionality, navigation, UI components, controllers, or any critical paths that E2E tests exercise. No E2E tags are warranted.

Performance Test Selection:
No performance-impacting changes. The backupUtils.ts refactor is a cosmetic method-chaining change with identical runtime behavior. No UI rendering, data loading, state management, or critical flow changes were made.

View GitHub Actions results

@NicolasMassart NicolasMassart added this pull request to the merge queue Jun 10, 2026
Merged via the queue into main with commit 15eb653 Jun 10, 2026
63 of 65 checks passed
@NicolasMassart NicolasMassart deleted the refactor/26686_e5-platform_migrate-event-builder branch June 10, 2026 09:45
@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 Jun 10, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 10, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.82.0 Issue or pull request that will be included in release 7.82.0 label Jun 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.82.0 Issue or pull request that will be included in release 7.82.0 risk:low AI analysis: low risk size-S team-mobile-platform Mobile Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants