
Security News
White House Authorizes Private Companies to Conduct Offensive Cyber Operations
A new federal program will let vetted U.S. cybersecurity firms help investigate and disrupt foreign cybercrime groups under government direction.
@metamask/analytics-controller
Advanced tools
@metamask/analytics-controllerCommon Analytics controller for event tracking across MetaMask client platforms.
yarn add @metamask/analytics-controller
or
npm install @metamask/analytics-controller
The AnalyticsController provides a unified interface for tracking analytics events, identifying users, and managing analytics preferences. It delegates client platform-specific implementation to an AnalyticsPlatformAdapter and integrates with the MetaMask messenger system for inter-controller communication.
[!NOTE] "Client platform" means mobile or extension
The controller does not persist state internally. The client platform is responsible for loading and persisting analytics settings. This design enables:
analyticsId before the controller is initialized, useful for other controllers or early startup codeLoad settings from storage before initializing the controller, then subscribe to AnalyticsController:stateChange events to persist any state changes.
| Field | Type | Description | Persisted |
|---|---|---|---|
analyticsId | string | UUIDv4 identifier (client platform-generated) | No |
optedIn | boolean | User opt-in status | Yes |
analyticsId Has No DefaultThe analyticsId uniquely identifies the user. If the controller generated a new ID on each boot, the ID would be ineffective. The client platform must generate a UUID on first run, persist it, and provide it to the controller constructor.
uuid package or client platform equivalentWhen isAnonymousEventsFeatureEnabled is enabled in the constructor, events with sensitive properties are split into separate events:
properties (uses user ID)properties and sensitiveProperties (uses anonymous ID)This allows sensitive data to be tracked anonymously while maintaining user identification for regular properties. When disabled (default), all properties are tracked in a single event.
onSetupCompletedCalled once after controller initialization with a guaranteed valid analyticsId. Use this for client platform-specific setup that requires the analytics ID (e.g., adding plugins). Errors in onSetupCompleted are caught and logged—they don't break the controller.
This package is part of a monorepo. Instructions for contributing can be found in the monorepo README.
FAQs
Common Analytics controller for event tracking
The npm package @metamask/analytics-controller receives a total of 57,516 weekly downloads. As such, @metamask/analytics-controller popularity was classified as popular.
We found that @metamask/analytics-controller demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A new federal program will let vetted U.S. cybersecurity firms help investigate and disrupt foreign cybercrime groups under government direction.

Research
/Security News
The campaign amassed more than 75,000 installs by targeting Russian-speaking users seeking access to blocked services.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.