refactor(analytics): migrate core UX metrics consumers#43432
Conversation
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/core-extension-ux (13 files, +114 -61)
|
cec68aa to
05a1960
Compare
|
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. |
Builds ready [05a1960]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs
|
05a1960 to
ce3e1c1
Compare
Builds ready [ce3e1c1]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs
|
ce3e1c1 to
7804e27
Compare
Builds ready [7804e27] [reused from ce3e1c1]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs
|
Refresh slice from main-synced monolithic branch.
7804e27 to
3b38fa6
Compare
Main migrated home to TypeScript (home.component.tsx + home.container.tsx). Apply isMetaMetricsEnabled tri-state selector changes to the new TSX files and remove the obsolete home.container.js. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [8d3677e]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs
|
There was a problem hiding this comment.
Pull request overview
This PR continues the Analytics Phase B migration by refactoring core UX surfaces to stop reading legacy MetaMetrics state (participateInMetaMetrics, metaMetricsId) and instead consume canonical analytics selectors (analyticsId, optedIn, completedMetaMetricsOnboarding) while preserving the intended tri-state consent behavior.
Changes:
- Migrates Privacy settings toggles and MetaMetrics data deletion flows to canonical consent/id selectors.
- Updates Home and multichain navigation entrypoints (Discover/Stake/Funding modal/global menu) to build Portfolio URLs using
analyticsIdand the new consent gate. - Adjusts tests and Storybook fixtures to use the new canonical state shape.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/pages/settings/privacy-tab/metametrics-item.tsx | Switches settings MetaMetrics toggle off legacy selector to canonical consent selectors. |
| ui/pages/settings/privacy-tab/delete-metametrics-data-item.tsx | Updates “delete MetaMetrics data” item enablement gate to completed && optedIn && analyticsId. |
| ui/pages/settings/privacy-tab/delete-metametrics-data-item.test.tsx | Updates selector mocks to match new consent/id selectors. |
| ui/pages/settings/privacy-tab/data-collection-item.tsx | Gates marketing consent toggle disablement on completed && optedIn instead of legacy participation flag. |
| ui/pages/home/home.container.tsx | Derives a canonical isMetaMetricsEnabled flag for Home from completed && optedIn. |
| ui/pages/home/home.component.tsx | Renames prop usage to isMetaMetricsEnabled and updates conditional UI. |
| ui/pages/home/home.component.test.tsx | Updates Home props builder for renamed MetaMetrics enabled prop. |
| ui/pages/home/home.component.stories.tsx | Updates Storybook props for renamed MetaMetrics enabled prop. |
| ui/components/multichain/token-list-item/stakeable-link.tsx | Uses canonical analytics id/consent to build Portfolio “stake” URL. |
| ui/components/multichain/menu-items/discover-menu-item.tsx | Uses canonical analytics id/consent to build Portfolio “discover” URL and update deps. |
| ui/components/multichain/menu-items/discover-menu-item.stories.tsx | Updates mock store to canonical analytics id + consent fields. |
| ui/components/multichain/global-menu-drawer/useGlobalMenuSections.tsx | Migrates Portfolio URL generation inputs to canonical analytics id + consent fields. |
| ui/components/multichain/funding-method-modal/funding-method-modal.tsx | Migrates Portfolio URL generation inputs to canonical analytics id + consent fields. |
| ui/components/app/modals/visit-support-data-consent-modal/visit-support-data.test.tsx | Updates selector usage in tests from metaMetricsId to analyticsId. |
| ui/components/app/modals/visit-support-data-consent-modal/visit-support-data-consent-modal.tsx | Uses analyticsId selector and renames internal param while preserving query key. |
| ui/components/app/metametrics-toggle/metametrics-toggle.tsx | Switches settings MetaMetrics toggle off legacy selector to canonical consent selectors. |
| ui/components/app/delete-metametrics-data-button/delete-metametrics-data-button.tsx | Migrates deletion button inputs to canonical selectors (id + consent). |
| ui/components/app/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx | Updates deletion button tests to mock canonical selectors. |
Comments suppressed due to low confidence (3)
ui/components/app/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx:132
- This test claims to cover the “analytics/metametrics id not available” case, but it currently only mocks
getOptedInasfalseand never setsgetAnalyticsIdtonull/undefined. If the button is disabled whenanalyticsIdis missing (which the component UI already accounts for), add an explicit test setup for that scenario.
// if user does not opt in to participate in metrics or for backup and sync, metametricsId will not be created.
it('should disable the data deletion button when there is metametrics id not available', async () => {
useSelectorMock.mockImplementation((selector) => {
if (selector === getCompletedMetaMetricsOnboarding) {
return true;
}
if (selector === getOptedIn) {
return false;
}
return undefined;
});
ui/pages/settings/privacy-tab/metametrics-item.tsx:103
- The toggle
valuepreviously treated “unset” (onboarding incomplete) as off (participateInMetaMetrics === true). UsingisOptedIndirectly can diverge from that tri-state behavior; gate with onboarding completion to match the legacy UI semantics.
<SettingsToggleItem
title={t(PRIVACY_ITEMS.metametrics)}
description={t('participateInMetaMetricsDescription')}
value={isOptedIn}
onToggle={handleToggle}
dataTestId="participate-in-meta-metrics-input"
containerDataTestId="participate-in-meta-metrics-toggle"
disabled={!useExternalServices}
/>
ui/components/app/metametrics-toggle/metametrics-toggle.tsx:119
- Gate the rendered toggle value with onboarding completion (
participateInMetaMetrics === true) to match the previousgetParticipateInMetaMetricsbehavior.
<ToggleButton
value={isOptedIn}
disabled={!useExternalServices}
onToggle={(value) => handleUseParticipateInMetaMetrics(!value)}
offLabel={t('off')}
onLabel={t('on')}
/>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Part 4 of the Analytics Phase B split (supersedes monolithic #43406).
Owner: @MetaMask/core-extension-ux
Reason: Core UX surfaces still depend on legacy metrics selectors.
Solution: Migrate home, privacy settings, multichain discover, delete-metametrics, metametrics-toggle, and visit-support modal to canonical analytics selectors.
Tri-state rule: Where old code used
getParticipateInMetaMetricsfor "metrics enabled", usegetCompletedMetaMetricsOnboarding(state) && getOptedIn(state).Depends on: #43430
Changelog
CHANGELOG entry: null
Related issues
Part of https://github.com/MetaMask/MetaMask-planning/issues/7331
Manual testing steps
yarn startand toggle metrics in Settings → PrivacyPre-merge author checklist
Pre-merge reviewer checklist