Skip to content

refactor(analytics): remove legacy metrics projection and selector shims#43442

Draft
gauthierpetetin wants to merge 1 commit into
mainfrom
refactor/analytics-phase-b-cleanup
Draft

refactor(analytics): remove legacy metrics projection and selector shims#43442
gauthierpetetin wants to merge 1 commit into
mainfrom
refactor/analytics-phase-b-cleanup

Conversation

@gauthierpetetin

@gauthierpetetin gauthierpetetin commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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 of participateInMetaMetrics / metaMetricsId and delete deprecated selector aliases from ui/selectors/metametrics.js and ui/selectors/selectors.js.

Do not merge until #43431#43441 are on main. Retarget/rebase to main before merging.

Depends on: #43430 and all consumer PRs (#43431#43441)

Changelog

CHANGELOG entry: null

Related issues

Fixes: MetaMask-planning#7331

Manual testing steps

  1. Grep for remaining legacy selector imports in ui/ and app/scripts/
  2. Run yarn start and verify metrics opt-in/out and portfolio links
  3. Run yarn build:test and a representative metrics E2E subset

Pre-merge author checklist

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.

@github-actions

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.

Base automatically changed from refactor/analytics-phase-b-foundation to main June 11, 2026 14:49
@gauthierpetetin gauthierpetetin force-pushed the refactor/analytics-phase-b-cleanup branch from 63d41e3 to cca4c33 Compare June 11, 2026 14:53
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#43431MetaMask#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>
@gauthierpetetin gauthierpetetin force-pushed the refactor/analytics-phase-b-cleanup branch from cca4c33 to 5956c0a Compare June 11, 2026 16:05
@github-actions github-actions Bot added size-M and removed size-S labels Jun 11, 2026
@metamaskbotv2

metamaskbotv2 Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
Builds ready [5956c0a] [reused from cca4c33]
Deprecated Browserify fallback builds
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 0 warn · 🔴 0 fail)

Baseline (latest main): 86afca4 | Date: 6/11/2026 | Pipeline: 27360438531 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-webpackfirefox-webpack
loadNewAccount
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
confirmTx
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
bridgeUserActions
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
User Journey Benchmarks · Samples: 5 · mock API

⚠️ Missing data: chrome/webpack/userJourneyAssets, chrome/webpack/userJourneyTransactions

Benchmarkchrome-webpackfirefox-webpack
onboardingImportWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
onboardingNewWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
importSrpHome
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
assetDetails
[Sentry log · main/release]
🟢 [CI log]
solanaAssetDetails
[Sentry log · main/release]
🟢 [CI log]
sendTransactions
[Sentry log · main/release]
🟢 [CI log]
swap
[Sentry log · main/release]
🟢 [CI log]
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-webpack
dappPageLoad
[Sentry log · main/release]
🟢 [CI log]
Bundle size diffs
  • background: -126 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: -200 Bytes (0%)

Refresh slice from main-synced monolithic branch.
@gauthierpetetin gauthierpetetin force-pushed the refactor/analytics-phase-b-cleanup branch from 5956c0a to 6c571e1 Compare June 12, 2026 04:33
@github-actions github-actions Bot added size-S and removed size-M labels Jun 12, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-S team-extension-platform Extension Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant