refactor(analytics): migrate platform misc UI and cross-domain E2E#43441
refactor(analytics): migrate platform misc UI and cross-domain E2E#43441gauthierpetetin wants to merge 1 commit into
Conversation
5e43986 to
31f18ad
Compare
Builds ready [31f18ad]
⚡ Performance Benchmarks (Total: 🟢 20 pass · 🟡 5 warn · 🔴 0 fail)
Bundle size diffs
|
|
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. |
31f18ad to
59cd57d
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 [59cd57d]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs
|
59cd57d to
d0ea222
Compare
Builds ready [d0ea222] [reused from 59cd57d]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs
|
Refresh slice from main-synced monolithic branch.
d0ea222 to
bb288b5
Compare
Builds ready [bb288b5]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs
|
There was a problem hiding this comment.
Pull request overview
This PR is part 13 of the Analytics Phase B split, migrating a set of “platform misc” UI surfaces and several cross-domain E2E specs off legacy MetaMetrics selectors (participateInMetaMetrics / metaMetricsId) onto canonical analytics fields (optedIn, completedMetaMetricsOnboarding, analyticsId).
Changes:
- Updated multiple UI consumers (error page, survey toast, coin overview, batch-sell empty state, asset page) to derive metrics enablement from
completedMetaMetricsOnboarding && optedInand to useanalyticsId. - Updated portfolio/navigation helpers and related call sites to pass
analyticsIdinstead of legacy IDs. - Migrated multiple E2E specs/fixtures/constants from
MOCK_META_METRICS_IDand legacy consent flags to canonical analytics equivalents.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ui/pages/unlock-page/unlock-page.stories.tsx | Updates story state to use canonical analytics consent fields. |
| ui/pages/error-page/error-page.component.tsx | Migrates metrics gating from legacy selector to canonical consent selectors. |
| ui/pages/error-page/error-component.test.tsx | Updates selector mocks/assertions to match canonical consent selectors. |
| ui/pages/batch-sell/pages/select/components/batch-sell-empty-select-tokens.tsx | Uses analyticsId + canonical consent selectors for portfolio navigation params. |
| ui/pages/batch-sell/pages/select/components/batch-sell-empty-select-tokens.test.tsx | Adjusts selector mocks and expectations for canonical analytics fields. |
| ui/pages/asset/components/asset-page.tsx | Switches portfolio URL construction to use analyticsId and canonical consent selectors. |
| ui/helpers/utils/portfolio.js | Renames the ID parameter to analyticsId and uses it in URL params. |
| ui/components/ui/survey-toast/survey-toast.tsx | Migrates survey fetch gating/URL construction to canonical analytics fields. |
| ui/components/app/wallet-overview/non-evm-overview.test.tsx | Updates mocked state from metaMetricsId to analyticsId. |
| ui/components/app/wallet-overview/coin-overview.tsx | Migrates portfolio click tracking/navigation to canonical analytics fields. |
| ui/components/app/modals/pna25-modal/pna25-modal.stories.tsx | Updates story state to canonical analytics consent fields. |
| test/e2e/tests/vault-corruption/vault-corruption.spec.ts | Updates fixtures to canonical analytics consent fields. |
| test/e2e/tests/survey/survey.spec.ts | Switches mocked survey endpoint to use MOCK_ANALYTICS_ID and canonical controller fields. |
| test/e2e/tests/remote-feature-flag/remote-feature-flag.spec.ts | Migrates fixtures/constants to canonical analytics fields. |
| test/e2e/tests/profile-metrics/profile-metrics.spec.ts | Migrates fixtures/test matrix to canonical analytics consent fields. |
| test/e2e/tests/portfolio/portfolio-site.spec.ts | Updates mocked portfolio URL assertions/fixtures to MOCK_ANALYTICS_ID. |
| test/e2e/tests/port-stream-chunking/port-stream-chunking.spec.ts | Updates fixtures/constants to canonical analytics fields. |
| test/e2e/tests/account/unlock-wallet.spec.ts | Updates Firefox onboarding metrics flow options to canonical consent fields. |
Comments suppressed due to low confidence (1)
ui/helpers/utils/portfolio.js:18
getPortfolioUrlcurrently stringifiesanalyticsId,metricsEnabled, andmarketingEnableddirectly into query params. Since UI state usesnullformetamask.analyticsIdandmetamask.dataCollectionForMarketingby default (seeui/ducks/metamask/metamask.js), this can produce URLs likemetametricsId=nullormarketingEnabled=null, which is unlikely to be intended and can break downstream parsing/analytics. Coerce these values to safe defaults before appending.
url.searchParams.append('metametricsId', analyticsId);
// Append privacy preferences for metrics + marketing on user navigation to Portfolio
url.searchParams.append('metricsEnabled', String(metricsEnabled));
url.searchParams.append('marketingEnabled', String(marketingEnabled));
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Builds ready [bb288b5]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs
|
Description
Part 13 of the Analytics Phase B split (supersedes monolithic #43406).
Owner: Extension Platform
Reason: Cross-cutting UI and E2E consumers still reference legacy metrics selectors.
Solution: Migrate error page, portfolio helper, survey toast, batch-sell, coin-overview, and cross-domain E2E specs to canonical analytics selectors.
Depends on: #43430
Changelog
CHANGELOG entry: null
Related issues
Part of https://github.com/MetaMask/MetaMask-planning/issues/7331
Manual testing steps
yarn startand verify portfolio/discover URL params with metrics on and offyarn build:testPre-merge author checklist
Pre-merge reviewer checklist