Skip to content

feat(wallet): wire AnalyticsController into default initialization - #10901

Open
gauthierpetetin wants to merge 8 commits into
mainfrom
feat/wallet-migrate-analytics-controller-init
Open

gauthierpetetin wants to merge 8 commits into
mainfrom
feat/wallet-migrate-analytics-controller-init

Conversation

@gauthierpetetin

@gauthierpetetin gauthierpetetin commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

NetworkController and SeedlessOnboardingController already call AnalyticsController:getState and AnalyticsController:trackEvent through the wallet root messenger, but hosts still had to construct and register AnalyticsController themselves.

This PR adds AnalyticsController to the default @metamask/wallet initialization configurations, matching other migrated controllers. Clients must supply instanceOptions.analyticsController.platformAdapter and analyticsId. Optional feature flags keep the controller defaults (false). Persisted state overrides the supplied analyticsId. The messenger delegates ConfigRegistry and Geolocation actions so event-purpose loading and optional geolocation enrichment work when hosts enable them.

References

  • Related to MUL-2022 (Migrate controllers initialization into Wallet Library)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them
    • Hosts must pass the new required analyticsController instance options and remove any existing root-messenger AnalyticsController registrations to avoid collisions.

Note

Medium Risk
Breaking wallet API: all integrators must supply analyticsController instance options and remove duplicate messenger registrations; mis-migration can cause startup failures or double registration.

Overview
@metamask/wallet now builds AnalyticsController as part of default initialization, so hosts must pass required instanceOptions.analyticsController (platformAdapter and analyticsId, plus optional feature flags). Persisted analytics state still wins over the supplied ID, and the controller messenger delegates Config Registry / Geolocation actions for purpose loading and optional geo enrichment.

This is a breaking integration change: any host that already registers AnalyticsController or no-op AnalyticsController:* handlers on the wallet root messenger must remove them to avoid registration collisions.

@metamask/wallet-cli is updated to match: the daemon wires a fixed CLI analytics ID and a no-op platform adapter via instance options and deletes the old root-messenger stub registration (and drops the direct @metamask/messenger dependency). Tests now assert opted-out, no-delivery analytics behavior instead of an empty analytics ID.

Reviewed by Cursor Bugbot for commit 9347ee3. Bugbot is set up for automated code reviews on this repo. Configure here.

Include AnalyticsController in the wallet library so hosts no longer register it separately, while still supplying the platform adapter and analytics id.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gauthierpetetin
gauthierpetetin requested review from a team as code owners October 20, 2026 09:32
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

Current version of PR was reviewed by /review-bugbot on Oct 20, 11:31 GMT+2. It flagged 0 findings.

Bugbot on commit 88ae5b1 is skipped.

Fix oxlint import style, add tsconfig references, link changelog PRs, and wire wallet-cli's required analyticsController options instead of colliding stub handlers.

Co-authored-by: Cursor <cursoragent@cursor.com>
jpuri
jpuri previously approved these changes Oct 20, 2026

@jpuri jpuri 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 in files owned by confirmations look good.

@gauthierpetetin

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@11.1.0-preview-64d459746
@metamask-previews/accounts-controller@40.1.0-preview-64d459746
@metamask-previews/address-book-controller@8.0.0-preview-64d459746
@metamask-previews/advanced-chart-core@1.0.0-preview-64d459746
@metamask-previews/ai-controllers@2.0.0-preview-64d459746
@metamask-previews/analytics-controller@4.0.0-preview-64d459746
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-64d459746
@metamask-previews/announcement-controller@9.0.0-preview-64d459746
@metamask-previews/app-metadata-controller@3.0.0-preview-64d459746
@metamask-previews/approval-controller@10.0.0-preview-64d459746
@metamask-previews/assets-controller@19.1.0-preview-64d459746
@metamask-previews/assets-controllers@112.1.2-preview-64d459746
@metamask-previews/authenticated-user-storage@4.1.0-preview-64d459746
@metamask-previews/base-controller@10.1.0-preview-64d459746
@metamask-previews/base-data-service@2.1.0-preview-64d459746
@metamask-previews/bitcoin-regtest-up@2.0.0-preview-64d459746
@metamask-previews/bridge-controller@82.0.3-preview-64d459746
@metamask-previews/bridge-status-controller@76.4.0-preview-64d459746
@metamask-previews/build-utils@4.0.0-preview-64d459746
@metamask-previews/chain-agnostic-permission@2.0.0-preview-64d459746
@metamask-previews/chomp-api-service@6.0.1-preview-64d459746
@metamask-previews/claims-controller@1.0.3-preview-64d459746
@metamask-previews/client-controller@2.0.0-preview-64d459746
@metamask-previews/client-utils@3.0.4-preview-64d459746
@metamask-previews/compliance-controller@3.0.0-preview-64d459746
@metamask-previews/composable-controller@13.0.0-preview-64d459746
@metamask-previews/config-registry-controller@5.0.0-preview-64d459746
@metamask-previews/connectivity-controller@1.0.0-preview-64d459746
@metamask-previews/controller-utils@13.0.0-preview-64d459746
@metamask-previews/core-backend@12.3.0-preview-64d459746
@metamask-previews/cryptography@1.1.2-preview-64d459746
@metamask-previews/delegation-controller@4.0.0-preview-64d459746
@metamask-previews/earn-controller@13.0.2-preview-64d459746
@metamask-previews/eip-5792-middleware@4.0.1-preview-64d459746
@metamask-previews/eip-7702-internal-rpc-middleware@1.0.0-preview-64d459746
@metamask-previews/eip1193-permission-middleware@3.0.0-preview-64d459746
@metamask-previews/eth-block-tracker@16.0.0-preview-64d459746
@metamask-previews/eth-json-rpc-middleware@25.0.0-preview-64d459746
@metamask-previews/eth-json-rpc-provider@7.0.0-preview-64d459746
@metamask-previews/foundryup@2.0.0-preview-64d459746
@metamask-previews/gas-fee-controller@27.0.0-preview-64d459746
@metamask-previews/gator-permissions-controller@6.0.1-preview-64d459746
@metamask-previews/geolocation-controller@2.0.0-preview-64d459746
@metamask-previews/java-tron-up@2.0.0-preview-64d459746
@metamask-previews/json-rpc-engine@11.0.0-preview-64d459746
@metamask-previews/json-rpc-middleware-stream@9.0.0-preview-64d459746
@metamask-previews/keyring-controller@28.2.0-preview-64d459746
@metamask-previews/kyc-controller@0.10.0-preview-64d459746
@metamask-previews/local-node-utils@2.0.0-preview-64d459746
@metamask-previews/logging-controller@10.0.0-preview-64d459746
@metamask-previews/marketing-consent-controller@1.0.0-preview-64d459746
@metamask-previews/message-manager@15.0.0-preview-64d459746
@metamask-previews/messenger@3.0.0-preview-64d459746
@metamask-previews/messenger-cli@1.0.0-preview-64d459746
@metamask-previews/mfa-recovery-controller@0.0.0-preview-64d459746
@metamask-previews/money-account-api-data-service@2.2.0-preview-64d459746
@metamask-previews/money-account-balance-service@3.1.2-preview-64d459746
@metamask-previews/money-account-controller@2.0.0-preview-64d459746
@metamask-previews/money-account-mfa-whitelist@0.1.0-preview-64d459746
@metamask-previews/money-account-upgrade-controller@5.1.0-preview-64d459746
@metamask-previews/money-account-utils@2.1.0-preview-64d459746
@metamask-previews/multichain-account-service@14.1.0-preview-64d459746
@metamask-previews/multichain-api-middleware@5.0.0-preview-64d459746
@metamask-previews/multichain-network-controller@4.0.0-preview-64d459746
@metamask-previews/multichain-transactions-controller@8.0.0-preview-64d459746
@metamask-previews/name-controller@10.0.0-preview-64d459746
@metamask-previews/network-connection-banner-controller@1.0.0-preview-64d459746
@metamask-previews/network-controller@37.1.0-preview-64d459746
@metamask-previews/network-enablement-controller@7.0.2-preview-64d459746
@metamask-previews/notification-services-controller@30.0.0-preview-64d459746
@metamask-previews/passkey-controller@4.1.0-preview-64d459746
@metamask-previews/permission-controller@14.0.0-preview-64d459746
@metamask-previews/permission-log-controller@6.0.0-preview-64d459746
@metamask-previews/perps-controller@20.1.0-preview-64d459746
@metamask-previews/phishing-controller@18.2.1-preview-64d459746
@metamask-previews/platform-api-docs@0.2.1-preview-64d459746
@metamask-previews/polling-controller@17.0.0-preview-64d459746
@metamask-previews/preferences-controller@24.0.0-preview-64d459746
@metamask-previews/profile-controller@1.1.0-preview-64d459746
@metamask-previews/profile-metrics-controller@5.1.3-preview-64d459746
@metamask-previews/profile-sync-controller@34.1.0-preview-64d459746
@metamask-previews/ramps-controller@27.0.1-preview-64d459746
@metamask-previews/rate-limit-controller@8.0.0-preview-64d459746
@metamask-previews/react-data-query@2.0.0-preview-64d459746
@metamask-previews/remote-feature-flag-controller@7.0.0-preview-64d459746
@metamask-previews/sample-controllers@6.0.0-preview-64d459746
@metamask-previews/seedless-onboarding-controller@12.0.0-preview-64d459746
@metamask-previews/selected-network-controller@27.0.0-preview-64d459746
@metamask-previews/sentinel-api-service@2.1.0-preview-64d459746
@metamask-previews/shield-controller@7.0.4-preview-64d459746
@metamask-previews/signature-controller@40.0.0-preview-64d459746
@metamask-previews/smart-transactions-controller@27.1.0-preview-64d459746
@metamask-previews/snap-account-service@4.0.0-preview-64d459746
@metamask-previews/social-controllers@3.8.0-preview-64d459746
@metamask-previews/solana-test-validator-up@2.0.0-preview-64d459746
@metamask-previews/stellar-quickstart-up@0.0.0-preview-64d459746
@metamask-previews/storage-service@2.0.0-preview-64d459746
@metamask-previews/subscription-controller@14.0.1-preview-64d459746
@metamask-previews/transaction-controller@72.2.1-preview-64d459746
@metamask-previews/transaction-pay-controller@30.1.0-preview-64d459746
@metamask-previews/transaction-pay-middleware@0.0.0-preview-64d459746
@metamask-previews/user-operation-controller@42.0.1-preview-64d459746
@metamask-previews/utils@12.0.0-preview-64d459746
@metamask-previews/wallet@18.0.1-preview-64d459746
@metamask-previews/wallet-cli@0.0.0-preview-64d459746

gauthierpetetin and others added 2 commits October 20, 2026 14:46
The analytics stub handlers that imported Messenger were removed when AnalyticsController moved into the wallet package.

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

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.

🟢 Approval recommended

No blocking defects were identified; remaining feedback concerns test strength and changelog ordering.

No open issues 🎉

What changed in this PR

Adds AnalyticsController to default wallet initialization and migrates the CLI from stub handlers to a no-op adapter.

Changes:

  • Requires host-provided analytics options, preserving persisted state precedence.
  • Delegates configuration and geolocation messenger calls.
  • Updates CLI integration, tests, dependencies, and migration notes.
File Description
yarn.lock Updates workspace dependencies.
packages/​wallet/​tsconfig.lint.json Adds analytics lint reference.
packages/​wallet/​tsconfig.json Adds analytics project reference.
packages/​wallet/​tsconfig.build.json Adds analytics build reference.
packages/​wallet/​src/​Wallet.test.ts Updates options and initialization count.
packages/​wallet/​src/​types.ts Requires analytics instance options.
packages/​wallet/​src/​initialization/​instances/​transaction-controller/​transaction-controller.test.ts Supplies analytics test options.
packages/​wallet/​src/​initialization/​instances/​index.ts Exports analytics initialization.
packages/​wallet/​src/​initialization/​instances/​gas-fee-controller/​gas-fee-controller.test.ts Supplies analytics test options.
packages/​wallet/​src/​initialization/​instances/​analytics-controller/​types.ts Defines required options and optional flags.
packages/​wallet/​src/​initialization/​instances/​analytics-controller/​analytics-controller.ts Constructs controller and delegates messenger access.
packages/​wallet/​src/​initialization/​instances/​analytics-controller/​analytics-controller.test.ts Tests initialization, state, and messaging.
packages/​wallet/​package.json Adds analytics dependency.
packages/​wallet/​CHANGELOG.md Documents breaking migration requirements.
packages/​wallet-cli/​tsconfig.lint.json Removes messenger lint reference.
packages/​wallet-cli/​tsconfig.json Removes messenger project reference.
packages/​wallet-cli/​tsconfig.build.json Removes messenger build reference.
packages/​wallet-cli/​src/​daemon/​wallet-factory.ts Replaces stubs with no-op analytics options.
packages/​wallet-cli/​src/​daemon/​wallet-factory.test.ts Checks adapter and identifier options.
packages/​wallet-cli/​src/​daemon/​wallet-factory.integration.test.ts Checks real controller state and tracking.
packages/​wallet-cli/​package.json Removes direct messenger dependency.
packages/​wallet-cli/​CHANGELOG.md Documents daemon analytics migration.

Review effort: Balanced

mcmire
mcmire previously approved these changes Oct 20, 2026

@mcmire mcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One suggestion for later, but LGTM otherwise.

Comment on lines +19 to +32
new AnalyticsController({
messenger,
platformAdapter: options.platformAdapter,
state: {
...getDefaultAnalyticsControllerState(),
analyticsId: options.analyticsId,
...state,
},
isAnonymousEventsFeatureEnabled: options.isAnonymousEventsFeatureEnabled,
isEventQueuePersistenceEnabled: options.isEventQueuePersistenceEnabled,
isPreConsentQueueEnabled: options.isPreConsentQueueEnabled,
isGeolocationEnabled: options.isGeolocationEnabled,
isEventFragmentsEnabled: options.isEventFragmentsEnabled,
}),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This isn't a blocker for merging this PR, but I wonder if AnalyticsController should take care of inserting this into the state? That way @metamask/wallet is kept sort of "dumb" and this section can be simplified to:

Suggested change
new AnalyticsController({
messenger,
platformAdapter: options.platformAdapter,
state: {
...getDefaultAnalyticsControllerState(),
analyticsId: options.analyticsId,
...state,
},
isAnonymousEventsFeatureEnabled: options.isAnonymousEventsFeatureEnabled,
isEventQueuePersistenceEnabled: options.isEventQueuePersistenceEnabled,
isPreConsentQueueEnabled: options.isPreConsentQueueEnabled,
isGeolocationEnabled: options.isGeolocationEnabled,
isEventFragmentsEnabled: options.isEventFragmentsEnabled,
}),
new AnalyticsController({
messenger,
platformAdapter: options.platformAdapter,
analyticsId: options.analyticsId,
isAnonymousEventsFeatureEnabled: options.isAnonymousEventsFeatureEnabled,
isEventQueuePersistenceEnabled: options.isEventQueuePersistenceEnabled,
isPreConsentQueueEnabled: options.isPreConsentQueueEnabled,
isGeolocationEnabled: options.isGeolocationEnabled,
isEventFragmentsEnabled: options.isEventFragmentsEnabled,
}),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I cleaned up the redundant getDefaultAnalyticsControllerState() merge in this commit (e58766a), since AnalyticsController already applies defaults in its constructor.

The wallet now only injects analyticsId and lets persisted state override it.
The larger suggestion (passing analyticsId as a top-level constructor option and dropping state assembly from @metamask/wallet) needs an change on AnalyticsController itself. I'll prepare a follow-up PR for it.

AnalyticsController already merges getDefaultAnalyticsControllerState in its constructor, so the wallet only needs to inject analyticsId and spread persisted state.

Co-authored-by: Cursor <cursoragent@cursor.com>
gauthierpetetin and others added 2 commits October 21, 2026 07:49
Spreading optional persisted state widens required fields, so assert AnalyticsControllerState after injecting analyticsId. The controller still merges defaults at runtime.

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

This branch was successfully deployed

1 active (outdated) deployment
default-branch — 88ae5b1d Deployed Oct 20, 2026 by gauthierpetetin via Determine whether this PR is a release PR #5678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants