[Bug]: analytics-controller.init() not awaited Segment events sent with userId: undefined for opted in users
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- analytics
Research direction
Start with app/scripts/messenger-client-init/analytics-controller-init.ts at line 63, then read the @metamask/analytics-controller 2.0.0 changelog entry about asynchronous init. Ensure initialization completes before startup analytics events are tracked, and verify that resulting Segment track/view payloads contain the analyticsId rather than undefined.
Written by the indexing model from the issue text.
Description
Describe the bug
AnalyticsController.init() is called without await in app/scripts/messenger-client-init/analytics-controller-init.ts (line 63), but @metamask/analytics-controller@2.0.0 (the version locked in yarn.lock) made init() asynchronous a breaking change explicitly documented in its CHANGELOG:
"AnalyticsController.init ... are now asynchronous and return a Promise, so await them before tracking events"
Inside init(), the call order is:
await #maybeResolveLocation()async geolocation network request (runs becauseisGeolocationEnabled: true)platformAdapter.onSetupCompleted(analyticsId)this setscachedAnalyticsIdin the platform adapter- Replay queued events
Because init() is not awaited, onSetupCompleted hasn't run yet when the first analytics events fire after startup. The platform adapter's cachedAnalyticsId variable remains undefined, so all track() and view() calls send Segment payloads with userId: undefined until the geolocation network request completes.
This affects all returning (already opted-in) users on every startup.
Expected behavior
All Segment track/view payloads include the correct userId (analyticsId). controller.init() must be awaited before any analytics events are tracked.
Screenshots/Recordings
No response
Steps to reproduce
- Be a returning MetaMask user (already opted in to analytics)
- Open MetaMask background service worker initializes AnalyticsController
- Any analytics event fired during the geolocation resolution window is sent to Segment with userId: undefined
Error messages or log output
No thrown error — silent data corruption.
Segment track/view payloads contain: { userId: undefined }
Root cause:
File: app/scripts/messenger-client-init/analytics-controller-init.ts, line 63
Current (buggy):
controller.init(); // Promise not awaited
Fix:
await controller.init();
Upstream CHANGELOG: https://github.com/MetaMask/core/blob/main/packages/analytics-controller/CHANGELOG.md#200
Where was this bug found?
Live version (from official store)
Version
12.x (main branch yarn.lock resolves @metamask/analytics-controller@2.0.0)
Build type
No response
Browser
Chrome
Operating system
Windows, Linux
Hardware wallet
No response
Additional context
Related to the @metamask/analytics-controller@2.0.0 upgrade. The CHANGELOG for that package explicitly warns that init() is now async and must be awaited, but analytics-controller-init.ts was not updated accordingly.
Severity
No response
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 443
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MetaMask/metamask-extension
-
regression-RC-13.50.0 Sev2-normal team-accounts-framework type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-extension#46445 ·
-
client-controller-update team-core-platform
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-extension#46426 ·
-
client-controller-update team-assets
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-extension#46393 ·
-
client-controller-update team-confirmations
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-extension#46384 ·
-
client-controller-update team-money-movement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-extension#46238 ·
All issues in MetaMask/metamask-extension
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100