Repository navigation
feat(wallet): wire AnalyticsController into default initialization - #10901
gauthierpetetin wants to merge 8 commits into
Conversation
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>
|
Current version of PR was reviewed by /review-bugbot on Oct 20, 11:31 GMT+2. It flagged 0 findings. Bugbot on commit |
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
left a comment
There was a problem hiding this comment.
Changes in files owned by confirmations look good.
…nalytics-controller-init
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
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>
There was a problem hiding this comment.
🟢 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
left a comment
There was a problem hiding this comment.
One suggestion for later, but LGTM otherwise.
| 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, | ||
| }), |
There was a problem hiding this comment.
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:
| 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, | |
| }), |
There was a problem hiding this comment.
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>
…nalytics-controller-init
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>
Explanation
NetworkControllerandSeedlessOnboardingControlleralready callAnalyticsController:getStateandAnalyticsController:trackEventthrough the wallet root messenger, but hosts still had to construct and registerAnalyticsControllerthemselves.This PR adds
AnalyticsControllerto the default@metamask/walletinitialization configurations, matching other migrated controllers. Clients must supplyinstanceOptions.analyticsController.platformAdapterandanalyticsId. Optional feature flags keep the controller defaults (false). Persisted state overrides the suppliedanalyticsId. The messenger delegates ConfigRegistry and Geolocation actions so event-purpose loading and optional geolocation enrichment work when hosts enable them.References
Checklist
analyticsControllerinstance options and remove any existing root-messengerAnalyticsControllerregistrations to avoid collisions.Note
Medium Risk
Breaking wallet API: all integrators must supply
analyticsControllerinstance options and remove duplicate messenger registrations; mis-migration can cause startup failures or double registration.Overview
@metamask/walletnow buildsAnalyticsControlleras part of default initialization, so hosts must pass requiredinstanceOptions.analyticsController(platformAdapterandanalyticsId, 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
AnalyticsControlleror no-opAnalyticsController:*handlers on the wallet root messenger must remove them to avoid registration collisions.@metamask/wallet-cliis 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/messengerdependency). 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.