refactor(analytics): remove legacy metrics projection and selector shims#43442
Draft
gauthierpetetin wants to merge 1 commit into
Draft
refactor(analytics): remove legacy metrics projection and selector shims#43442gauthierpetetin wants to merge 1 commit into
gauthierpetetin wants to merge 1 commit into
Conversation
This was referenced Jun 11, 2026
343aa6f to
63d41e3
Compare
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. |
63d41e3 to
cca4c33
Compare
pull Bot
pushed a commit
to Reality2byte/metamask-extension
that referenced
this pull request
Jun 11, 2026
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>
cca4c33 to
5956c0a
Compare
7 tasks
Contributor
Builds ready [5956c0a] [reused from cca4c33]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 0 warn · 🔴 0 fail)
Bundle size diffs
|
Refresh slice from main-synced monolithic branch.
5956c0a to
6c571e1
Compare
pull Bot
pushed a commit
to Reality2byte/metamask-extension
that referenced
this pull request
Jun 12, 2026
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Part 14 of the Analytics Phase B split (supersedes monolithic #43406). (final)
Owner: Extension Platform
Reason: After all consumers migrate, legacy projection and deprecated selector aliases are no longer needed.
Solution: Remove
getState()projection ofparticipateInMetaMetrics/metaMetricsIdand delete deprecated selector aliases fromui/selectors/metametrics.jsandui/selectors/selectors.js.Do not merge until #43431–#43441 are on
main. Retarget/rebase tomainbefore merging.Depends on: #43430 and all consumer PRs (#43431–#43441)
Changelog
CHANGELOG entry: null
Related issues
Fixes: MetaMask-planning#7331
Manual testing steps
ui/andapp/scripts/yarn startand verify metrics opt-in/out and portfolio linksyarn build:testand a representative metrics E2E subsetPre-merge author checklist
Pre-merge reviewer checklist