refactor: E5 migrate MetricsEventBuilder to AnalyticsEventBuilder in onboarding components#31019
Conversation
…oarding components Replace legacy MetricsEventBuilder with AnalyticsEventBuilder across onboarding-related components and their tests, and clean up no-op setSaveDataRecording calls.
|
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. |
…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>
…tform_migrate-event-builder
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
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: |
Description
Migrates onboarding-related components from the legacy
MetricsEventBuilder(located inapp/core/Analytics/) to the newAnalyticsEventBuilder(located inapp/util/analytics/), as part of the broaderuseMetrics→useAnalyticsanalytics migration.Changes:
MetricsEventBuilder.createEventBuildercalls withAnalyticsEventBuilder.createEventBuilderinDeleteWalletModal,AccountStatus,backupUtils, and their testsbackupUtilsto the fluent chain pattern consistent with the rest of the codebase.setSaveDataRecording(true)calls from the migrated components (the method is a compatibility shim pending full removal in a follow-up PR)app/core/Analytics/README.mdto point toAnalyticsEventBuilderas the canonical builder and marksMetricsEventBuilderas legacyjest.mocked()instead ofas jest.Mocktype assertionsChangelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/MOBILE-26686
Manual testing steps
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)
trace()for usage andaddTokenfor an examplePre-merge reviewer checklist
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 legacyMetricsEventBuilderunderapp/core/Analytics/.backupUtilsnow builds onboarding tracking events with a single fluent chain (createEventBuilder→addProperties→build) beforetrackOnboarding, matching the pattern used elsewhere.actionButtonTracking.test.tsmocks and importsAnalyticsEventBuilderfrom the util path and usesjest.mocked()for typings.app/core/Analytics/README.mdnamesAnalyticsEventBuilderas the canonical builder, marksMetricsEventBuilderas 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.