Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@NicolasMassart
Copy link
Contributor

@NicolasMassart NicolasMassart commented Oct 31, 2025

Main

Explanation

New @metamask/analytics-controller package for unified, platform-agnostic analytics tracking controller for MetaMask.
This controller is designed for both the extension and mobile.

Changes

  • new analytics-controller package
  • initial setup of the package files
  • initial unit tests
  • initial documentation

Important

The adapter type is work in progress and will be updated as we
integrate with the new analytics system on mobile.
We have this draft type to help us iterate on the implementation.
It will be updated with proper types as we create the mobile adapter
And the controller package will be released only when this is completed.

Mobile side tests

Implemented the controller as a local resolution with "@metamask/analytics-controller@^1.0.0": "file:../core/packages/analytics-controller",
and all the init process.
It loads well.
image

Mobile not ready yet to PR as controller is not published.

References

fixes MetaMask/metamask-mobile#21854
Mobile PR MetaMask/metamask-mobile#22076

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, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Note

Introduces @metamask/analytics-controller with event/page tracking, user identification, state/messenger integration, tests/docs, and repo wiring.

  • New Package: @metamask/analytics-controller
    • Controller: AnalyticsController with methods trackEvent, identify, trackPage, enable/disable, optIn/optOut; default state via getDefaultAnalyticsControllerState() (UUIDv4 analyticsId).
    • Types/Adapters: AnalyticsPlatformAdapter and action types (AnalyticsController-*-action-types).
    • Messaging: Registers method action handlers under AnalyticsController:*.
    • Tooling: package.json, jest.config.js (100% coverage thresholds), tsconfig/build configs, typedoc, CHANGELOG.md, licenses, README with usage.
    • Tests: Unit tests for state init, methods, and messenger actions.
  • Monorepo Integration:
    • Add package to README.md (list + mermaid graph), .github/CODEOWNERS, tsconfig.json, tsconfig.build.json, and yarn.lock.

Written by Cursor Bugbot for commit a631fb0. This will update automatically on new commits. Configure here.

@NicolasMassart NicolasMassart changed the title Feat: new analytics controller Phase 1 Feat: new analytics controller [Phase 1] Oct 31, 2025
@NicolasMassart NicolasMassart changed the title Feat: new analytics controller [Phase 1] Feat(analytics): new analytics controller [Phase 1] Oct 31, 2025
…ific code

- Remove platform identifier from state and adapter interface
- Remove AnalyticsEventOptions (isOptIn, excludeFromMetrics)
- Remove eventsTracked counter from state
- Consolidate enable/disable into setEnabled(enabled?: boolean) with default true
- Make setOptedIn accept optional parameter with default true
- Make all tracking methods synchronous (remove Promise<void>)
- Update messenger type to follow pattern with AllowedActions/AllowedEvents
- Update BaseController to use literal 'AnalyticsController' type
- Simplify README to minimal format matching other controllers
@NicolasMassart NicolasMassart changed the title Feat(analytics): new analytics controller [Phase 1] Feat(analytics): new analytics controller [Phase 1.1] Oct 31, 2025
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

I know this is in draft but I couldn't help but review this now :)

NicolasMassart and others added 6 commits October 31, 2025 20:01
… method exposure

- Add MESSENGER_EXPOSED_METHODS for automatic method action handlers
- Generate method action types using generate-method-action-types
- Consolidate types into controller file (state, messenger, actions)
- Rename types.ts to more specific AnalyticsPlatformAdapter.types.ts
- Update test helper from withController to setupController
- Match file organization pattern used in sample-controllers
@NicolasMassart NicolasMassart marked this pull request as ready for review November 3, 2025 16:00
cursor[bot]

This comment was marked as outdated.

@MetaMask MetaMask deleted a comment from github-actions bot Nov 4, 2025
@NicolasMassart
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "2.0.0-preview-81bccf77",
  "@metamask-previews/accounts-controller": "34.0.0-preview-81bccf77",
  "@metamask-previews/address-book-controller": "7.0.0-preview-81bccf77",
  "@metamask-previews/analytics-controller": "0.0.0-preview-81bccf77",
  "@metamask-previews/announcement-controller": "8.0.0-preview-81bccf77",
  "@metamask-previews/app-metadata-controller": "2.0.0-preview-81bccf77",
  "@metamask-previews/approval-controller": "8.0.0-preview-81bccf77",
  "@metamask-previews/assets-controllers": "87.0.0-preview-81bccf77",
  "@metamask-previews/base-controller": "9.0.0-preview-81bccf77",
  "@metamask-previews/bridge-controller": "59.0.0-preview-81bccf77",
  "@metamask-previews/bridge-status-controller": "59.0.0-preview-81bccf77",
  "@metamask-previews/build-utils": "3.0.4-preview-81bccf77",
  "@metamask-previews/chain-agnostic-permission": "1.2.2-preview-81bccf77",
  "@metamask-previews/composable-controller": "12.0.0-preview-81bccf77",
  "@metamask-previews/controller-utils": "11.15.0-preview-81bccf77",
  "@metamask-previews/core-backend": "4.0.0-preview-81bccf77",
  "@metamask-previews/delegation-controller": "1.0.0-preview-81bccf77",
  "@metamask-previews/earn-controller": "9.0.0-preview-81bccf77",
  "@metamask-previews/eip-5792-middleware": "2.0.0-preview-81bccf77",
  "@metamask-previews/eip-7702-internal-rpc-middleware": "0.1.0-preview-81bccf77",
  "@metamask-previews/eip1193-permission-middleware": "1.0.2-preview-81bccf77",
  "@metamask-previews/ens-controller": "18.0.0-preview-81bccf77",
  "@metamask-previews/error-reporting-service": "3.0.0-preview-81bccf77",
  "@metamask-previews/eth-block-tracker": "14.0.0-preview-81bccf77",
  "@metamask-previews/eth-json-rpc-middleware": "21.0.0-preview-81bccf77",
  "@metamask-previews/eth-json-rpc-provider": "5.0.1-preview-81bccf77",
  "@metamask-previews/foundryup": "1.0.1-preview-81bccf77",
  "@metamask-previews/gas-fee-controller": "25.0.0-preview-81bccf77",
  "@metamask-previews/gator-permissions-controller": "0.3.0-preview-81bccf77",
  "@metamask-previews/json-rpc-engine": "10.1.1-preview-81bccf77",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.8-preview-81bccf77",
  "@metamask-previews/keyring-controller": "24.0.0-preview-81bccf77",
  "@metamask-previews/logging-controller": "7.0.0-preview-81bccf77",
  "@metamask-previews/message-manager": "14.0.0-preview-81bccf77",
  "@metamask-previews/messenger": "0.3.0-preview-81bccf77",
  "@metamask-previews/multichain-account-service": "2.1.0-preview-81bccf77",
  "@metamask-previews/multichain-api-middleware": "1.2.4-preview-81bccf77",
  "@metamask-previews/multichain-network-controller": "2.0.0-preview-81bccf77",
  "@metamask-previews/multichain-transactions-controller": "6.0.0-preview-81bccf77",
  "@metamask-previews/name-controller": "9.0.0-preview-81bccf77",
  "@metamask-previews/network-controller": "25.0.0-preview-81bccf77",
  "@metamask-previews/network-enablement-controller": "3.1.0-preview-81bccf77",
  "@metamask-previews/notification-services-controller": "19.0.0-preview-81bccf77",
  "@metamask-previews/permission-controller": "12.1.0-preview-81bccf77",
  "@metamask-previews/permission-log-controller": "5.0.0-preview-81bccf77",
  "@metamask-previews/phishing-controller": "15.0.0-preview-81bccf77",
  "@metamask-previews/polling-controller": "15.0.0-preview-81bccf77",
  "@metamask-previews/preferences-controller": "21.0.0-preview-81bccf77",
  "@metamask-previews/profile-sync-controller": "26.0.0-preview-81bccf77",
  "@metamask-previews/rate-limit-controller": "7.0.0-preview-81bccf77",
  "@metamask-previews/remote-feature-flag-controller": "2.0.0-preview-81bccf77",
  "@metamask-previews/sample-controllers": "3.0.0-preview-81bccf77",
  "@metamask-previews/seedless-onboarding-controller": "6.1.0-preview-81bccf77",
  "@metamask-previews/selected-network-controller": "25.0.0-preview-81bccf77",
  "@metamask-previews/shield-controller": "1.2.0-preview-81bccf77",
  "@metamask-previews/signature-controller": "35.0.0-preview-81bccf77",
  "@metamask-previews/subscription-controller": "3.2.0-preview-81bccf77",
  "@metamask-previews/token-search-discovery-controller": "4.0.0-preview-81bccf77",
  "@metamask-previews/transaction-controller": "61.1.0-preview-81bccf77",
  "@metamask-previews/transaction-pay-controller": "3.0.0-preview-81bccf77",
  "@metamask-previews/user-operation-controller": "40.0.0-preview-81bccf77"
}

@NicolasMassart NicolasMassart force-pushed the feat/21854_new_analytics_controller branch from 82556b0 to e5e7db2 Compare November 5, 2025 17:06
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-project-automation github-project-automation bot moved this from Needs dev review to Review finalised - Ready to be merged in PR review queue Nov 5, 2025
@NicolasMassart NicolasMassart merged commit 9d1a6d6 into main Nov 6, 2025
266 checks passed
@NicolasMassart NicolasMassart deleted the feat/21854_new_analytics_controller branch November 6, 2025 08:15
@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 Nov 6, 2025
Gudahtt added a commit that referenced this pull request Nov 7, 2025
There was a new package added in #7017 that had no entry in `teams.json`. It
has been added.
@Gudahtt Gudahtt mentioned this pull request Nov 7, 2025
4 tasks
Gudahtt added a commit that referenced this pull request Nov 7, 2025
There was a new package added in #7017 that had no entry in `teams.json`. It
has been added.
Gudahtt added a commit that referenced this pull request Nov 7, 2025
## Explanation

There was a new package added in #7017 that had no entry in
`teams.json`. It has been added.

## References

Related to #7017

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is
generating a summary for commit
bcb720f. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

feat(analytics): Create @metamask/analytics-controller Package in core [Phase 1.1]

5 participants