refactor(analytics): migrate onboarding-flow to analytics selectors#43431
Conversation
|
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. |
✨ Files requiring CODEOWNER review ✨🔐 @MetaMask/web3auth (11 files, +56 -56)
|
a46ecc7 to
8cd43a7
Compare
Builds ready [8cd43a7]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs
|
8cd43a7 to
cfa7f76
Compare
MetaMask#43430) ## **Description** Part 1 of the Analytics Phase B split (supersedes monolithic MetaMask#43406). **Reason:** Phase B migrates off legacy `participateInMetaMetrics` / `metaMetricsId` toward canonical `analyticsId`, `optedIn`, and `completedMetaMetricsOnboarding`. **Solution:** This PR lands the shared foundation: Redux initial state, selectors, metrics context, background/Sentry/controller wiring, and messenger/service inits. It also adds temporary backward-compat shims so domain PRs can merge in parallel. **Shim contract (removed in MetaMask#43442):** | Legacy | Replacement | Shim behavior | |--------|-------------|---------------| | `getParticipateInMetaMetrics` | `completed && optedIn` | deprecated alias | | `getIsParticipateInMetaMetricsSet` | `getCompletedMetaMetricsOnboarding` | alias | | `getMetaMetricsId` | `getAnalyticsId` | alias | | `state.metamask.metaMetricsId` | `state.metamask.analyticsId` | projected in `getState()` | | `state.metamask.participateInMetaMetrics` | derived from canonical fields | projected in `getState()` | **Merge order:** Must merge before consumer PRs (MetaMask#43431–MetaMask#43441). ## **Changelog** CHANGELOG entry: null ## **Related issues** Part of MetaMask/MetaMask-planning#7331 ## **Manual testing steps** 1. Run `yarn start` and load the extension 2. Complete onboarding metrics opt-in and opt-out flows 3. Toggle metrics in Settings → Privacy 4. Confirm the extension loads without background selector errors <!-- ## **Screenshots/Recordings** ### **Before** ### **After** --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/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** > Changes how analytics consent and user ID are read everywhere events, Sentry, OAuth buffering, and sampling run; behavior should match the old model but the split onboarding/opt-in gates add regression surface across privacy flows. > > **Overview** > **Phase B foundation** for analytics: the extension stops treating `participateInMetaMetrics` and `metaMetricsId` as the source of truth and wires **`analyticsId`**, **`optedIn`**, and **`completedMetaMetricsOnboarding`** through Redux, background, controllers, and Sentry. > > The UI Redux slice and selectors now expose the canonical fields (`getOptedIn`, `getCompletedMetaMetricsOnboarding`, `getAnalyticsId`), with **deprecated aliases** for `getParticipateInMetaMetrics`, `getIsParticipateInMetaMetricsSet`, and `getMetaMetricsId`. `MetaMetricsProvider` gates buffering and immediate tracking on **onboarding complete + opt-in + analytics ID** instead of the old combined flag. > > Background and services apply the same split: `AppOpened` / `AppInstalled` / dapp-viewed sampling, cookie handler setup, OAuth event buffering, uninstall URL encoding, data-deletion Segment calls, and RPC degraded/unavailable sampling all read **`analyticsId`** and require **`completedMetaMetricsOnboarding && optedIn`** where metrics used to check `participateInMetaMetrics`. Messenger inits fetch the ID via **`AnalyticsController:getState`** rather than `MetaMetricsController:getMetaMetricsId`. > > Sentry helpers are renamed and reshaped (`getAnalyticsState`, `AnalyticsParticipation`) so transport, breadcrumbs, and the MetaMetrics integration drop or send events based on the two consent booleans and attach `user.id` from `analyticsId`. `getState()` in the main controller still **projects** legacy `participateInMetaMetrics` / `metaMetricsId` for parallel consumer PRs. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7311dbb. 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>
Builds ready [cfa7f76]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs
|
cfa7f76 to
2e2465b
Compare
Builds ready [2e2465b] [reused from cfa7f76]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs
|
Refresh slice from main-synced monolithic branch.
2e2465b to
5a37f8d
Compare
Builds ready [5a37f8d]
⚡ Performance Benchmarks (Total: 🟢 20 pass · 🟡 5 warn · 🔴 0 fail)
Bundle size diffs
|
…Mask#43467) ## **Description** Part 2 of the Analytics Phase B split (supersedes monolithic MetaMask#43406). After foundation ([MetaMask#43430](MetaMask#43430)) merged, child analytics PRs failed `yarn lint:tsc` because migrated E2E tests used canonical fields (`analyticsId`, `optedIn`, `MOCK_ANALYTICS_ID`) while unmigrated tests still used legacy fields (`metaMetricsId`, `participateInMetaMetrics`, `MOCK_META_METRICS_ID`). This PR adds transitional dual-support in E2E fixtures and flow helpers so domain PRs ([MetaMask#43431](https://github.com/MetaMask/metamask-extension/pull/43431)–[#43441](https://github.com/MetaMask/metamask-extension/pull/43441)) can merge in parallel. Cleanup ([MetaMask#43442](MetaMask#43442)) removes this shim last. **Changes:** - `test/e2e/constants.ts` — `MOCK_ANALYTICS_ID` plus deprecated `MOCK_META_METRICS_ID` alias - `test/e2e/fixtures/fixture-builder-v2.ts` — `withMetaMetricsController` accepts legacy and canonical patch fields - `test/e2e/page-objects/flows/onboarding.flow.ts` — `OnboardingMetricsFlowOptions` with `resolveOptedIn()` - `test/e2e/page-objects/flows/vault-corruption.flow.ts` — accepts canonical onboarding metrics options ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: MetaMask/MetaMask-planning#7331 (partial) ## **Manual testing steps** 1. None, E2E tests shall pass as before <!-- ## **Screenshots/Recordings** ### **Before** ### **After** --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/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** > Test-only helpers and constants; no production wallet or analytics runtime behavior changes. > > **Overview** > Adds a **transitional dual-support layer** in E2E so analytics migration PRs can land in parallel without `yarn lint:tsc` failures from mixed legacy and canonical naming. > > **Constants:** Introduces `MOCK_ANALYTICS_ID` and keeps `MOCK_META_METRICS_ID` as a deprecated alias to the same value. > > **Fixtures:** `withMetaMetricsController` now accepts both legacy (`metaMetricsId`, `participateInMetaMetrics`) and canonical (`analyticsId`, `optedIn`) patches, resolves them with canonical taking precedence for IDs, and writes `AnalyticsController` state (`analyticsId`, `optedIn`) while still merging real `MetaMetricsController` fields. > > **Onboarding flows:** New `OnboardingMetricsFlowOptions` and `resolveOptedIn()` unify opt-in behavior; flows accept `optedIn` alongside deprecated `participateInMetaMetrics`. Post-metrics wait accepts either `analyticsId` or `metaMetricsId` in app state. > > **Vault corruption:** `onboardThenExecuteScript` / `onboardThenTriggerCorruptionFlow` use the shared metrics options type and forward `optedIn`. > > Intended to be removed by a follow-up cleanup PR once all E2E tests use canonical fields. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1f05308. 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>
There was a problem hiding this comment.
Pull request overview
This PR continues the Analytics Phase B migration by updating onboarding-flow UI/pages, related unit tests, the subscription support hook, and onboarding E2E coverage to read analytics state via the canonical selectors (getOptedIn, getCompletedMetaMetricsOnboarding, getAnalyticsId) instead of legacy MetaMetrics selectors/fields.
Changes:
- Migrates multiple onboarding flow routes/pages to
getCompletedMetaMetricsOnboarding/getOptedIn/getAnalyticsId. - Updates onboarding-flow unit tests to use
analyticsId,optedIn, andcompletedMetaMetricsOnboardingin mocked state. - Updates onboarding E2E fixture patching to use canonical analytics fields.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ui/pages/onboarding-flow/welcome/welcome.tsx | Switches onboarding routing gate from legacy “participation set” selector to getCompletedMetaMetricsOnboarding. |
| ui/pages/onboarding-flow/welcome/welcome.test.tsx | Updates mock state to use analyticsId instead of metaMetricsId. |
| ui/pages/onboarding-flow/setup-passkey/setup-passkey.tsx | Uses getCompletedMetaMetricsOnboarding to decide whether to show MetaMetrics step. |
| ui/pages/onboarding-flow/onboarding-flow-switch/onboarding-flow-switch.tsx | Updates redirect logic to depend on getCompletedMetaMetricsOnboarding. |
| ui/pages/onboarding-flow/metametrics/metametrics.tsx | Migrates checkbox initialization to use getOptedIn + getCompletedMetaMetricsOnboarding. |
| ui/pages/onboarding-flow/metametrics/metametrics.test.tsx | Updates mocked state to canonical optedIn / completedMetaMetricsOnboarding. |
| ui/pages/onboarding-flow/download-app/download-app.test.tsx | Updates test state override typing and defaults to canonical analytics fields. |
| ui/pages/onboarding-flow/creation-successful/creation-successful.tsx | Uses getOptedIn to decide whether MetricsOptIn/Out is tracked. |
| ui/pages/onboarding-flow/create-password/create-password.tsx | Migrates iframe injection + routing decisions to canonical analytics selectors/fields. |
| ui/pages/onboarding-flow/create-password/create-password.test.tsx | Updates mocked state to canonical optedIn / completedMetaMetricsOnboarding. |
| ui/hooks/subscription/useSubscription.ts | Replaces getMetaMetricsId usage with getAnalyticsId for support-link attribution. |
| test/e2e/tests/onboarding/onboarding.spec.ts | Updates fixture patch to use completedMetaMetricsOnboarding / optedIn / analyticsId. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Part 3 of the Analytics Phase B split (supersedes monolithic #43406).
Owner: @MetaMask/web3auth
Reason: Onboarding and subscription flows still read legacy metrics selectors.
Solution: Migrate onboarding-flow pages/tests,
useSubscription.ts, and onboarding E2E togetOptedIn,getCompletedMetaMetricsOnboarding, andgetAnalyticsId.Depends on: #43430
Changelog
CHANGELOG entry: null
Related issues
Part of https://github.com/MetaMask/MetaMask-planning/issues/7331
Manual testing steps
yarn startand complete create-wallet and import-wallet onboarding flowsyarn build:testthenyarn test:e2e:single test/e2e/tests/onboarding/onboarding.spec.ts --browser=chromePre-merge author checklist
Pre-merge reviewer checklist