feat: integrate analytics controller#42885
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/core-extension-ux (9 files, +24 -22)
👨🔧 @MetaMask/extension-platform (4 files, +10 -7)
🕵️ @MetaMask/extension-privacy-reviewers (1 files, +0 -1)
💎 @MetaMask/metamask-assets (1 files, +2 -2)
📜 @MetaMask/policy-reviewers (8 files, +64 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 🧪 @MetaMask/qa (5 files, +10 -8)
📈 @MetaMask/ramp (2 files, +2 -2)
🔄 @MetaMask/swaps-engineers (1 files, +37 -3)
👨🔧 @MetaMask/wallet-integrations (3 files, +9 -7)
🔐 @MetaMask/web3auth (5 files, +50 -25)
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Builds ready [2b95db2]
⚡ Performance Benchmarks (Total: 🟢 12 pass · 🟡 13 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [2e57540]
⚡ Performance Benchmarks (Total: 🟢 13 pass · 🟡 2 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [27c93f3]
⚡ Performance Benchmarks (Total: 🟢 23 pass · 🟡 2 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
|
||
| const EXTENSION_UNINSTALL_URL = 'https://metamask.io/uninstalled'; | ||
|
|
||
| export const overrideAnonymousEventNames = { |
There was a problem hiding this comment.
This logic is now moved to app/scripts/controllers/analytics/platform-adapter.ts
|
|
||
| // The function is used to build a unique messageId for segment messages | ||
| // It uses actionId and uniqueIdentifier from event if present | ||
| const buildUniqueMessageId = (args: { |
There was a problem hiding this comment.
messageId is no longer needed, as now managed by the AnalyticsController
| * the `anonymous` flag. | ||
| */ | ||
| const controllerMetadata: StateMetadata<MetaMetricsControllerState> = { | ||
| metaMetricsId: { |
There was a problem hiding this comment.
metaMetricsId is replaced by AnalyticsController's analyticsId
| includeInDebugSnapshot: true, | ||
| usedInUi: true, | ||
| }, | ||
| participateInMetaMetrics: { |
There was a problem hiding this comment.
participateInMetaMetrics is replaced by MetaMetricsController's completedMetaMetricsOnboarding and AnalyticsController's optedIn
| includeInDebugSnapshot: true, | ||
| usedInUi: false, | ||
| }, | ||
| segmentApiCalls: { |
There was a problem hiding this comment.
segmentApiCalls is replaced by AnalyticsController's eventQueue
| ) { | ||
| return submitRequestToBackground('trackMetaMetricsPage', [ | ||
| { ...payload, actionId: generateActionId() }, | ||
| options, |
There was a problem hiding this comment.
The only file calling trackMetaMetricsPage is ui/contexts/metametrics.tsx, and it no longer has options to pass.
The only option was isOptInPath, but we've removed it in this PR as it was a legacy UI-routing exception, that was no longer used.
| event: 'Fake Event', | ||
| category: 'Unit Test', | ||
| }, | ||
| { flushImmediately: true }, |
There was a problem hiding this comment.
flushImmediately option wasn't used anywhere in the codebase, and is now removed with this PR
| spy.mock.calls[0][1], | ||
| ); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
These "anonymous event names" tests are removed because correponding behavior no longer belongs to MetaMetricsController. It's been moved to app/scripts/controllers/analytics/platform-adapter.ts.
| }); | ||
| }); | ||
|
|
||
| describe('deterministic messageId', function () { |
There was a problem hiding this comment.
messageId is no longer managed by MetaMetricsController, it's now managed by the AnalyticsController
| }); | ||
| }); | ||
|
|
||
| describe('submitting segmentApiCalls to segment SDK', function () { |
There was a problem hiding this comment.
Persisted event queue (segmentApiCalls) is no longer managed by MetaMetricsController, it's now managed by the AnalyticsController
Builds ready [37d047e]
⚡ Performance Benchmarks (Total: 🟢 23 pass · 🟡 2 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 82af9d0. Configure here.
Builds ready [82af9d0]
⚡ Performance Benchmarks (Total: 🟢 21 pass · 🟡 4 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [9ca4546]
⚡ Performance Benchmarks (Total: 🟢 23 pass · 🟡 2 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [08a46b1]
⚡ Performance Benchmarks (Total: 🟢 23 pass · 🟡 1 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|

Description
This PR integrates AnalyticsController in Extension codebase.
It replaces this state:
metaMetricsIdparticipateInMetaMetricssegmentApiCallsby this state:
analyticsIdoptedIneventQueuecompletedMetaMetricsOnboardingSince these changes impact many areas of the codebase, we’ve decided to take a phased approach.
This PR migrates the persisted state and updates the UI compatibility selectors, as well as the background
getState()function, to derive the legacy values (metaMetricsId,participateInMetaMetrics) from the new state. This lets existing code continue using the legacy values while the source of truth moves toAnalyticsController.analyticsId,AnalyticsController.optedIn, andMetaMetricsController.completedMetaMetricsOnboarding.In future phases, we’ll progressively remove all remaining usages of the legacy values (
metaMetricsId,participateInMetaMetrics) throughout the codebase.The files that deserve more attention during PR review are the following:
flowchart TB subgraph Before["Before"] direction LR MMC1["MetaMetricsController"] --> SDK1["Segment SDK"] Early1["Early events"] --> SDK1 end subgraph After["After"] direction LR MMC2["MetaMetricsController"] --> AC["AnalyticsController"] AC --> SDK2["Segment SDK"] Early2["Early events"] --> SDK2 end Before ~~~ AfterChangelog
CHANGELOG entry: null
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/7193
Manual testing steps
Main test case
MetaMask Extension [Dev], except if you configured SEGMENT_WRITE_KEY env variable with your own Segment project), and filter events with your metaMetricsId/analyticsIda. track
b. identify
c. page
Edge cases
messageId(example: "signature-3947127447", and "signature-3947127447-success" or "signature-3947127447-failure"), while with this PR,messageIdhave a new uuidv4 format and events from a same fragment don't have similarmessageId(example: "9e3a83d0-ce13-47d2-a2f4-08a6d9adc29d" and "d2368a25-01c5-4b3c-af55-7d5f54eb58a6")timestampandsentAtScreenshots/Recordings
NA
Pre-merge author checklist
Pre-merge reviewer checklist
Note
High Risk
Changes consent, identity, Segment delivery, anonymous/sensitive event splitting, opt-out, and data-deletion IDs across the extension; behavioral differences in message IDs and offline queue retry are called out in the PR.
Overview
This PR moves MetaMetrics onto
AnalyticsControlleras the source of truth for consent and identity, while keeping legacymetaMetricsId/participateInMetaMetricsavailable via aggregatedgetState()for callers that have not migrated yet.MetaMetricsControllerno longer ownsmetaMetricsId,participateInMetaMetrics, orsegmentApiCalls. Opt-in/out now callsAnalyticsController:optIn/optOut, IDs come fromanalyticsId, and track / identify / page go through messenger actions. A newplatform-adaptersends Segment payloads (includingproperties.anonymous→ shared anonymous ID and renamed anon event names for signatures/transactions).completedMetaMetricsOnboardingreplaces storing participation on MMC. Direct Segment wiring, ID generation,segmentApiCallsMV3 replay, and deterministicmessageId/ fragment suffix behavior are removed from MMC.Call sites shift to
AnalyticsControllerstate (RPC rate limiting, data deletionsubjectIds, early/critical Segment helpers, Sentry allowlist). Tests and Segment shims are updated for the delegation model.Reviewed by Cursor Bugbot for commit 08a46b1. Bugbot is set up for automated code reviews on this repo. Configure here.