Skip to content

Commit b64014f

Browse files
refactor(analytics): migrate Batch 3-15: mobile-platform (#26591)
## **Description** Phase 3 analytics migration (Batch 3-15): migrate the ResetPassword view from `MetaMetrics.getInstance()` / `MetricsEventBuilder` to the new `analytics` utility and `AnalyticsEventBuilder`. **Reason**: Deprecate MetaMetrics in favour of the shared analytics utility and AnalyticsController. **Changes**: `ResetPassword/index.js` now uses `analytics.trackEvent()` and `AnalyticsEventBuilder` from `app/util/analytics`; test mocks updated to mock the analytics utility instead of MetaMetrics. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-302 (Batch 3-15) ## **Manual testing steps** ```gherkin Feature: Settings analytics Scenario: user triggers a password change event Given app is open and user is in Settings > Change Password flow When user performs an action that triggers analytics (e.g. password change confirmation) 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] > **Low Risk** > Low risk refactor limited to analytics plumbing in the password reset flow; main risk is mis-tracking or missing the `PASSWORD_CHANGED` event due to the API swap. > > **Overview** > Migrates `ResetPassword` analytics from legacy `MetaMetrics.getInstance()`/`MetricsEventBuilder` to the shared `analytics` utility with `AnalyticsEventBuilder`, keeping the `PASSWORD_CHANGED` event and its biometry-related properties. > > Updates the `ResetPassword` tests to mock `util/analytics/analytics` instead of `MetaMetrics`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 22501d0. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 3424cca commit b64014f

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

app/components/Views/ResetPassword/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ import Icon, {
5959
} from '../../../component-library/components/Icons/Icon';
6060
import Routes from '../../../constants/navigation/Routes';
6161
import NavigationService from '../../../core/NavigationService';
62-
import { MetaMetricsEvents, MetaMetrics } from '../../../core/Analytics';
63-
import { MetricsEventBuilder } from '../../../core/Analytics/MetricsEventBuilder';
62+
import { MetaMetricsEvents } from '../../../core/Analytics';
63+
import { AnalyticsEventBuilder } from '../../../util/analytics/AnalyticsEventBuilder';
64+
import { analytics } from '../../../util/analytics/analytics';
6465
import Checkbox from '../../../component-library/components/Checkbox';
6566
import fox from '../../../animations/Searching_Fox.json';
6667
import LottieView from 'lottie-react-native';
@@ -513,13 +514,13 @@ class ResetPassword extends PureComponent {
513514

514515
// Track password changed event
515516
const { biometryChoice } = this.state;
516-
const eventBuilder = MetricsEventBuilder.createEventBuilder(
517+
const eventBuilder = AnalyticsEventBuilder.createEventBuilder(
517518
MetaMetricsEvents.PASSWORD_CHANGED,
518519
).addProperties({
519520
biometry_type: this.state.biometryType,
520521
biometrics_enabled: Boolean(biometryChoice),
521522
});
522-
MetaMetrics.getInstance().trackEvent(eventBuilder.build());
523+
analytics.trackEvent(eventBuilder.build());
523524

524525
this.setState({ loading: false });
525526
this.props.navigation.navigate('SecuritySettings');

app/components/Views/ResetPassword/index.test.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,12 @@ jest.mock('react-native/Libraries/Alert/Alert', () => ({
108108
alert: jest.fn(),
109109
}));
110110

111-
const mockMetricsIsEnabled = jest.fn().mockReturnValue(true);
112111
const mockTrackEvent = jest.fn();
113-
jest.mock('../../../core/Analytics/MetaMetrics', () => ({
114-
getInstance: () => ({
115-
isEnabled: mockMetricsIsEnabled,
116-
trackEvent: mockTrackEvent,
117-
updateDataRecordingFlag: jest.fn(),
118-
}),
112+
jest.mock('../../../util/analytics/analytics', () => ({
113+
analytics: {
114+
trackEvent: (...args: unknown[]) => mockTrackEvent(...args),
115+
isEnabled: jest.fn().mockReturnValue(true),
116+
},
119117
}));
120118

121119
const mockRunAfterInteractions = jest.fn().mockImplementation((cb) => {

0 commit comments

Comments
 (0)