Skip to content

chore(wallet): migrate Analytics and Geolocation init into wallet - #47284

Merged
gauthierpetetin merged 10 commits into
mainfrom
chore/wallet-analytics-controller-init
Oct 27, 2026
Merged

gauthierpetetin merged 10 commits into
mainfrom
chore/wallet-analytics-controller-init

Conversation

@gauthierpetetin

@gauthierpetetin gauthierpetetin commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Bump @metamask/wallet to v20 (with @metamask/analytics-controller ^4.1.0 and @metamask/geolocation-controller ^2.0.0) and move AnalyticsController, GeolocationController, and GeolocationApiService ownership into the wallet package.

Reason: Wallet now constructs and owns these controllers, so the extension should stop initializing them through messenger-client-init. Putting geolocation inside wallet also guarantees its action handlers are registered before AnalyticsController.init() runs for returning opted-in users (location enrichment).

Solution:

  • Supply client-specific options from wallet-init (getAnalyticsControllerInstanceOptions, getGeolocationApiServiceInstanceOptions) and the analytics init messenger.
  • Remove the messenger-client-init factories / init modules for Analytics and Geolocation.
  • Resolve instances via wallet.getInstance('AnalyticsController') and wallet.getInstance('GeolocationController').
  • Call geolocation from the UI through root messenger actions (GeolocationController:getGeolocation / GeolocationController:refreshGeolocation) instead of adding new legacy background API methods.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

  1. Run the extension from this branch.
  2. Complete onboarding, including metrics consent choices.
  3. Unlock the wallet and perform a simple action that previously emitted analytics (for example open the home screen or switch network).
  4. Confirm the background loads without errors about missing AnalyticsController, GeolocationController, or messenger factories.
  5. Toggle metrics opt-in/opt-out in Settings and confirm the preference still applies.
  6. Open a flow that uses geo checks (for example mUSD conversion where available) and confirm country detection still works, including refresh if the UI exposes it.
  7. For a returning profile already opted into analytics, confirm startup still succeeds and location-enriched analytics do not fail with missing GeolocationController:getGeolocationData handler errors.

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.

Own AnalyticsController through @metamask/wallet v19 so extension init
only supplies client options and the init messenger.

Co-authored-by: Cursor <cursoragent@cursor.com>
@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.

@metamask-ci metamask-ci Bot added the team-extension-platform Extension Platform team label Oct 22, 2026
@gauthierpetetin gauthierpetetin self-assigned this Oct 22, 2026
…s-controller-init

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	app/scripts/metamask-controller.js
@socket-security

socket-security Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​metamask/​wallet@​18.0.0 ⏵ 20.0.096 -210077 +199 +150
Updated@​metamask/​analytics-controller@​4.0.0 ⏵ 4.1.099 -110010097 +1100

View full report

@metamask-ci

metamask-ci Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

✨ Files requiring CODEOWNER review ✨

🫰 @MetaMask/core-platform (1 files, +6 -11)
  • 📁 app/
    • 📁 scripts/
      • 📄 metamask-controller.js +6 -11

👨‍🔧 @MetaMask/earn (2 files, +12 -8)
  • 📁 ui/
    • 📁 hooks/
      • 📁 musd/
        • 📄 useMusdGeoBlocking.test.ts +5 -3
        • 📄 useMusdGeoBlocking.ts +7 -5

👨‍🔧 @MetaMask/extension-platform (1 files, +6 -11)
  • 📁 app/
    • 📁 scripts/
      • 📄 metamask-controller.js +6 -11

📜 @MetaMask/policy-reviewers (8 files, +168 -8)
  • 📁 lavamoat/
    • 📁 webpack/
      • 📁 mv2/
        • 📁 beta/
          • 📄 policy.json +21 -1
        • 📁 experimental/
          • 📄 policy.json +21 -1
        • 📁 flask/
          • 📄 policy.json +21 -1
        • 📁 main/
          • 📄 policy.json +21 -1
      • 📁 mv3/
        • 📁 beta/
          • 📄 policy.json +21 -1
        • 📁 experimental/
          • 📄 policy.json +21 -1
        • 📁 flask/
          • 📄 policy.json +21 -1
        • 📁 main/
          • 📄 policy.json +21 -1

Tip

Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Missing LavaMoat permissions block protected background startup, and the migrated initializer loses existing regression coverage.

2 open issues
What changed in this PR

Moves AnalyticsController ownership into @metamask/wallet, while retaining extension-specific analytics configuration in wallet-init.

Changes:

  • Upgrades @metamask/wallet to v19 and updates transitive dependencies.
  • Supplies analytics options through wallet initialization and retrieves the wallet-owned controller.
  • Removes the legacy initializer and updates messenger imports and wiring tests.
File Description
yarn.lock Locks wallet v19 and updated transitive dependencies.
package.json Bumps the wallet dependency to v19.
app/​scripts/​wallet-init/​messengers/​analytics-controller-messenger.ts Retains the extension analytics init messenger.
app/​scripts/​wallet-init/​messengers/​analytics-controller-messenger.test.ts Tests init messenger delegation.
app/​scripts/​wallet-init/​instance-options/​analytics-controller.ts Supplies extension-specific analytics options and setup.
app/​scripts/​wallet-init/​initialization.ts Passes analytics options to the wallet.
app/​scripts/​wallet-init/​initialization.test.ts Tests analytics option wiring.
app/​scripts/​metamask-controller.js Retrieves analytics from the wallet instead of client initialization.
app/​scripts/​messenger-client-init/​messengers/​index.ts Removes the legacy analytics messenger factory.
app/​scripts/​messenger-client-init/​analytics-controller-init.ts Deletes the extension-owned controller initializer.
app/​scripts/​messenger-client-init/​analytics-controller-init.test.ts Deletes the old initializer regression test.
app/​scripts/​lib/​createRPCMethodTrackingMiddleware.test.js Updates the analytics messenger import.
app/​scripts/​controllers/​analytics/​platform-adapter.ts Updates the messenger type import.
app/​scripts/​controllers/​analytics/​analytics.ts Updates the messenger type import.
app/​scripts/​controllers/​analytics/​analytics.test.ts Updates the analytics messenger import.

Review effort: Balanced

Comment thread package.json Resolved
@gauthierpetetin

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-policies

@metamask-ci

metamask-ci Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

No CI run found for this commit. Please wait for CI to start and retry @metamaskbot update-policies.

@gauthierpetetin

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-policies

@metamask-ci

metamask-ci Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

No CI run found for this commit. Please wait for CI to start and retry @metamaskbot update-policies.

gauthierpetetin and others added 2 commits October 22, 2026 17:16
Cover getAnalyticsControllerInstanceOptions registering Chain Value
Order and Perps Tab Badge mappings without duplicates.

Co-authored-by: Cursor <cursoragent@cursor.com>
Allow @metamask/wallet to import @metamask/analytics-controller after
the v19 bump across MV2 and MV3 policy variants.

Co-authored-by: Cursor <cursoragent@cursor.com>
@metamask-ci

metamask-ci Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor
Builds ready [ba026df]
⚡ Performance Benchmarks (Total: 🟢 11 pass · 🟡 0 warn · 🔴 0 fail)

Baseline (latest main): 171ed20 | Date: 7/28/2026 | Pipeline: 39804656837 | 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
Benchmarkchrome-webpackfirefox-webpack
onboardingImportWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
onboardingNewWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-webpack
dappPageLoad
[Sentry log · main/release]
🟢 [CI log]

📈 Results compared to the previous 5 runs on main

  • ↓ dappPageLoad/pageLoadTime: -62%
  • ↓ dappPageLoad/domContentLoaded: -13%
  • ↓ dappPageLoad/firstPaint: -46%
  • ↓ dappPageLoad/firstContentfulPaint: -46%
Bundle Size Diffs [🚀 Bundle size reduced!]
Status Bundle Total Diff Change
✅ background 15.46 MiB -1.61 KiB -0.01%
✅ ui 19.34 MiB -2.47 KiB -0.01%
✅ common 0 Bytes 0 Bytes 0.00%
✅ other 4.44 MiB -2.53 KiB -0.06%
✅ content scripts 3.24 MiB -5.06 KiB -0.15%
✅ zip 24.01 MiB -825 Bytes 0.00%

@gauthierpetetin

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-policies

@metamask-ci

metamask-ci Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Policies updated.
👀 Please review the diff for suspicious new powers.

Tip

Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers.
🧠 Learn how to read policy diffs: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

👀 lavamoat/webpack/mv2/beta/policy.json changes differ from lavamoat/webpack/mv2/main/policy.json changes
👀 lavamoat/webpack/mv2/experimental/policy.json changes differ from lavamoat/webpack/mv2/main/policy.json changes
👀 lavamoat/webpack/mv2/flask/policy.json changes differ from lavamoat/webpack/mv2/main/policy.json changes
👀 lavamoat/webpack/mv3/beta/policy.json changes differ from lavamoat/webpack/mv3/main/policy.json changes
👀 lavamoat/webpack/mv3/experimental/policy.json changes differ from lavamoat/webpack/mv3/main/policy.json changes
👀 lavamoat/webpack/mv3/flask/policy.json changes differ from lavamoat/webpack/mv3/main/policy.json changes

@metamask-ci

metamask-ci Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor
Builds ready [4da0313]
⚡ Performance Benchmarks (Total: 🟢 11 pass · 🟡 0 warn · 🔴 0 fail)

Baseline (latest main): 171ed20 | Date: 7/28/2026 | Pipeline: 39824619677 | 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
Benchmarkchrome-webpackfirefox-webpack
onboardingImportWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
onboardingNewWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-webpack
dappPageLoad
[Sentry log · main/release]
🟢 [CI log]

📈 Results compared to the previous 5 runs on main

  • ↓ dappPageLoad/pageLoadTime: -67%
  • ↓ dappPageLoad/domContentLoaded: -24%
  • ↓ dappPageLoad/firstPaint: -55%
  • ↓ dappPageLoad/firstContentfulPaint: -55%
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
Status Bundle Total Diff Change
🚨 background 15.47 MiB +1.71 KiB +0.01%
🚨 ui 19.34 MiB +3.06 KiB +0.02%
✅ common 0 Bytes 0 Bytes 0.00%
✅ other 4.44 MiB -35 Bytes 0.00%
✅ content scripts 3.23 MiB -10.83 KiB -0.33%
✅ zip 24.01 MiB +198 Bytes 0.00%

@metamask-ci

metamask-ci Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor
Builds ready [e7f32d4]
⚡ Performance Benchmarks (Total: 🟢 6 pass · 🟡 5 warn · 🔴 2 fail)

Baseline (latest main): 171ed20 | Date: 7/28/2026 | Pipeline: 40355659960 | Baseline logs

Metricschrome-webpackfirefox-webpack
loadNewAccount
[Sentry log · main/release]
🔴 load_new_account(p95) [CI log]🔴 load_new_account(p95) [CI log]

Regressions (🔴 2 failures)

Interaction Benchmarks · Samples: 5 🔴 2
Benchmarkchrome-webpackfirefox-webpack
loadNewAccount
[Sentry log · main/release]
🔴 [CI log]
🔴 load_new_account
🔴 [CI log]
🔴 load_new_account
confirmTx
[Sentry log · main/release]
🟡 [CI log]🟡 [CI log]
bridgeUserActions
[Sentry log · main/release]
🟡 [CI log]🟡 [CI log]

📈 Results compared to the previous 5 runs on main

  • ↑ loadNewAccount/load_new_account: +417%
  • ↑ loadNewAccount/total: +417%
  • ↑ loadNewAccount/fcp: +10%
  • ↑ confirmTx/longTaskTotalDuration: +64%
  • ↑ confirmTx/longTaskMaxDuration: +97%
  • ↑ confirmTx/tbt: +110%
  • ↑ confirmTx/fcp: +11%
  • ↑ bridgeUserActions/bridge_load_page: +94%
  • ↑ bridgeUserActions/bridge_load_asset_picker: +49%
  • ↑ bridgeUserActions/longTaskCount: +67%
  • ↑ bridgeUserActions/longTaskTotalDuration: +155%
  • ↑ bridgeUserActions/longTaskMaxDuration: +58%
  • ↑ bridgeUserActions/tbt: +293%
  • ↑ bridgeUserActions/total: +12%
  • ↑ loadNewAccount/load_new_account: +421%
  • ↑ loadNewAccount/total: +421%
  • ↑ loadNewAccount/fcp: +20%
  • ↑ loadNewAccount/lcp: +1298%
  • ↓ confirmTx/longTaskCount: -100%
  • ↓ confirmTx/longTaskTotalDuration: -100%
  • ↓ confirmTx/longTaskMaxDuration: -100%
  • ↓ confirmTx/tbt: -100%
  • ↓ confirmTx/inp: -17%
  • ↓ confirmTx/fcp: -31%
  • ↑ confirmTx/lcp: +1380%
  • ↑ bridgeUserActions/bridge_load_page: +289%
  • ↑ bridgeUserActions/bridge_load_asset_picker: +151%
  • ↓ bridgeUserActions/longTaskCount: -100%
  • ↓ bridgeUserActions/longTaskTotalDuration: -100%
  • ↓ bridgeUserActions/longTaskMaxDuration: -100%
  • ↓ bridgeUserActions/tbt: -100%
  • ↑ bridgeUserActions/total: +40%
  • ↑ bridgeUserActions/inp: +62%
  • ↑ bridgeUserActions/fcp: +29%
  • ↑ bridgeUserActions/lcp: +1334%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 1.9s
  • 🟡 confirmTx/FCP: p75 1.9s
  • 🟡 bridgeUserActions/FCP: p75 1.9s
  • 🟡 loadNewAccount/FCP: p75 2.1s
  • 🟡 confirmTx/LCP: p75 2.5s
  • 🟡 bridgeUserActions/FCP: p75 2.2s
  • 🟡 bridgeUserActions/LCP: p75 2.5s
Startup Benchmarks · Samples: 100
Benchmarkchrome-webpackfirefox-webpack
startupStandardHome
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]

📈 Results compared to the previous 5 runs on main

  • ↑ startupStandardHome/domInteractive: +12%
  • ↓ startupStandardHome/firstReactRender: -99%
  • ↓ startupStandardHome/initialActions: -33%
  • ↑ startupStandardHome/setupStore: +142%
  • ↓ startupStandardHome/longTaskCount: -33%
  • ↓ startupStandardHome/domInteractive: -24%
  • ↓ startupStandardHome/firstReactRender: -98%
  • ↓ startupStandardHome/initialActions: -50%
  • ↑ startupStandardHome/setupStore: +131%
  • ↓ startupStandardHome/fcp: -14%
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-webpackfirefox-webpack
onboardingImportWallet
[Sentry log · main/release]
🟢 [CI log]🟡 [CI log]
🟡 total
onboardingNewWallet
[Sentry log · main/release]
🟢 [CI log]🟢 [CI log]

📈 Results compared to the previous 5 runs on main

  • ↑ onboardingImportWallet/srpButtonToSrpForm: +47%
  • ↑ onboardingImportWallet/confirmSrpToPwForm: +47%
  • ↑ onboardingImportWallet/pwFormToMetricsScreen: +39%
  • ↑ onboardingImportWallet/metricsToWalletReadyScreen: +35%
  • ↓ onboardingImportWallet/doneButtonToHomeScreen: -94%
  • ↓ onboardingImportWallet/openAccountMenuToAccountListLoaded: -75%
  • ↓ onboardingImportWallet/longTaskCount: -86%
  • ↓ onboardingImportWallet/longTaskTotalDuration: -96%
  • ↓ onboardingImportWallet/longTaskMaxDuration: -93%
  • ↓ onboardingImportWallet/tbt: -100%
  • ↓ onboardingImportWallet/total: -89%
  • ↑ onboardingNewWallet/srpButtonToPwForm: +18%
  • ↑ onboardingNewWallet/skipBackupToMetricsScreen: +11%
  • ↓ onboardingNewWallet/doneButtonToAssetList: -83%
  • ↓ onboardingNewWallet/longTaskCount: -69%
  • ↓ onboardingNewWallet/longTaskTotalDuration: -75%
  • ↓ onboardingNewWallet/longTaskMaxDuration: -41%
  • ↓ onboardingNewWallet/tbt: -87%
  • ↓ onboardingNewWallet/total: -79%
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-webpack
dappPageLoad
[Sentry log · main/release]
🟢 [CI log]

📈 Results compared to the previous 5 runs on main

  • ↓ dappPageLoad/pageLoadTime: -57%
  • ↓ dappPageLoad/firstPaint: -41%
  • ↓ dappPageLoad/firstContentfulPaint: -41%
Bundle Size Diffs [🚀 Bundle size reduced!]
Status Bundle Total Diff Change
✅ background 15.42 MiB -49.96 KiB -0.32%
✅ ui 19.24 MiB -108.9 KiB -0.55%
✅ common 0 Bytes 0 Bytes 0.00%
✅ other 4.44 MiB -367 Bytes -0.01%
✅ content scripts 3.23 MiB -10.12 KiB -0.30%
🚨 zip 24.03 MiB +22.99 KiB +0.09%

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The consent-sensitive initialization migration needs human verification of startup, metrics preferences, and geolocation in a LavaMoat-enabled build.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@gauthierpetetin

Copy link
Copy Markdown
Contributor Author

@MetaMask/policy-reviewers LavaMoat policies are updated for the @metamask/wallet bump that now owns Analytics + Geolocation init. Same shape across all 8 webpack policy variants.

Intentional changes:

  • @metamask/wallet gains packages access to @metamask/analytics-controller and @metamask/geolocation-controller (expected imports, no new globals/builtins on wallet).
  • New nested resource @metamask/geolocation-controller>@metamask/controller-utils (path rewrite). Globals: Buffer.from, console.error, fetch, setTimeout. fetch/setTimeout match existing controller-utils needs.

@gauthierpetetin gauthierpetetin changed the title chore(analytics): move AnalyticsController init into wallet chore(wallet): migrate Analytics and Geolocation init into wallet Oct 26, 2026
@github-project-automation github-project-automation Bot moved this to Needs dev review in PR review queue Oct 26, 2026

@naugtur naugtur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

policy changes approved

@github-project-automation github-project-automation Bot moved this from Needs dev review to Review finalised - Ready to be merged in PR review queue Oct 27, 2026
@gauthierpetetin
gauthierpetetin added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 9330e70 Oct 27, 2026
161 of 162 checks passed
@gauthierpetetin
gauthierpetetin deleted the chore/wallet-analytics-controller-init branch October 27, 2026 10:07
@github-project-automation github-project-automation Bot moved this from Review finalised - Ready to be merged to Merged, Closed or Archived in PR review queue Oct 27, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 27, 2026
@metamaskbot metamaskbot added the release-13.56.0 Issue or pull request that will be included in release 13.56.0 label Nov 2, 2026
@gauthierpetetin

Copy link
Copy Markdown
Contributor Author

No release label on PR. Adding release label release-13.56.0 on PR, as PR was added to branch 13.56.0 when release was cut.

This branch was successfully deployed

1 active and 1 inactive deployments
segment-schema — e7f32d4a Deployed Oct 26, 2026 by gauthierpetetin via propose #346
pr-comment — e7f32d4a Deployed Oct 26, 2026 by gauthierpetetin via identify-codeowners #87290
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.56.0 Issue or pull request that will be included in release 13.56.0 size-L team-extension-platform Extension Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants