Skip to content

Conversation

@NicolasMassart
Copy link
Contributor

@NicolasMassart NicolasMassart commented Jan 15, 2026

Explanation

This PR introduces a new @metamask/analytics-privacy-controller package that provides GDPR/CCPA data deletion functionality for analytics data. The package allows to extract the logic from the mobile app (and will be compatible with extension too)

Current state: MetaMask mobile app currently has a dedicated mechanism to handle user data deletion requests for analytics data in compliance with GDPR and CCPA regulations.

Solution: This package introduces:

  • AnalyticsPrivacyController: A controller that manages the lifecycle of data deletion requests, tracks whether new data has been recorded since the last deletion request, and stores deletion regulation metadata (ID and timestamp)
  • AnalyticsPrivacyService: A service that communicates with Segment's Regulations API via a proxy endpoint to create deletion tasks and check their status
  • State management: Tracks dataRecorded flag, deleteRegulationId, and deleteRegulationTimestamp to support compliance workflows
  • Selectors: Provides reusable selectors for accessing controller state

Implementation details:

  • The controller calls AnalyticsController:getState to retrieve the user's analytics ID
  • It delegates to AnalyticsPrivacyService to make HTTP requests to Segment's Regulations API
  • The service uses createServicePolicy from @metamask/controller-utils for retry logic and error handling
  • State is persisted and can be used to determine if new analytics events have been recorded since the last deletion request
  • The package includes comprehensive test coverage (100% branch, function, line, and statement coverage)

References

see also MetaMask/metamask-mobile#22016

Fixes #7618

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

Note

Introduces @metamask/analytics-privacy-controller as a new package to manage analytics data deletion workflows.

  • Adds AnalyticsPrivacyController with actions to create/check deletion tasks, expose timestamps/IDs, and track hasCollectedDataSinceDeletionRequest; publishes related events and selectors
  • Adds AnalyticsPrivacyService to call a proxy to Segment Regulations API (POST create, GET status) with retry/circuit-breaker policy via @metamask/controller-utils
  • Exposes types, logger, tests (controller/service/selectors) and package build/test configs; wires package into monorepo (README, CODEOWNERS, teams.json, tsconfig, yarn.lock)

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

NicolasMassart and others added 6 commits January 15, 2026 14:21
…ad of dates

- Changed `deleteRegulationDate` to `deleteRegulationTimestamp` in the state and related methods to store timestamps in milliseconds since epoch.
- Updated relevant methods and tests to reflect the new timestamp format.
- Removed date formatting logic and adjusted selectors accordingly.
- Added new dependencies for testing and updated the test suite to ensure proper functionality with the new timestamp format.

This change enhances consistency in handling date-related data within the analytics privacy controller.
@socket-security
Copy link

socket-security bot commented Jan 15, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@NicolasMassart NicolasMassart marked this pull request as draft January 15, 2026 18:17
NicolasMassart and others added 3 commits January 16, 2026 11:06
…e PascalCase

- Refactored enum values in `DataDeleteResponseStatus` and `DataDeleteStatus` to follow PascalCase naming convention.
- Updated all references in the codebase and tests to ensure consistency with the new enum values.
- This change enhances code readability and aligns with common TypeScript practices.
@NicolasMassart NicolasMassart marked this pull request as ready for review January 16, 2026 14:32
@NicolasMassart NicolasMassart requested a review from a team as a code owner January 16, 2026 14:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new @metamask/analytics-privacy-controller package that provides GDPR/CCPA data deletion functionality for analytics data, extracting logic from the mobile app for reuse across MetaMask clients.

Changes:

  • New controller package with AnalyticsPrivacyController for managing data deletion state (tracks dataRecorded, deleteRegulationId, and deleteRegulationTimestamp)
  • AnalyticsPrivacyService for communicating with Segment's Regulations API via proxy endpoint with retry/circuit-breaker logic
  • Comprehensive test coverage (100% branch, function, line, and statement coverage) and selector utilities for state access

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/analytics-privacy-controller/src/AnalyticsPrivacyController.ts Main controller implementation managing deletion request lifecycle and state
packages/analytics-privacy-controller/src/AnalyticsPrivacyService.ts Service for HTTP communication with Segment Regulations API via proxy
packages/analytics-privacy-controller/src/types.ts Type definitions for deletion statuses and API responses
packages/analytics-privacy-controller/src/selectors.ts Reusable state selectors
packages/analytics-privacy-controller/src/constants.ts Segment API constants
packages/analytics-privacy-controller/package.json Package configuration with dependencies
packages/analytics-privacy-controller/*.test.ts Comprehensive test suites for controller and service
yarn.lock Lockfile updates for new package dependencies
tsconfig.json, tsconfig.build.json TypeScript project references
teams.json, .github/CODEOWNERS Team ownership configuration
README.md Documentation updates including package in list and dependency graph

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@NicolasMassart
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

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": "4.0.0-preview-fa81dffb",
  "@metamask-previews/accounts-controller": "35.0.2-preview-fa81dffb",
  "@metamask-previews/address-book-controller": "7.0.1-preview-fa81dffb",
  "@metamask-previews/analytics-controller": "1.0.0-preview-fa81dffb",
  "@metamask-previews/analytics-privacy-controller": "0.0.0-preview-fa81dffb",
  "@metamask-previews/announcement-controller": "8.0.0-preview-fa81dffb",
  "@metamask-previews/app-metadata-controller": "2.0.0-preview-fa81dffb",
  "@metamask-previews/approval-controller": "8.0.0-preview-fa81dffb",
  "@metamask-previews/assets-controller": "0.0.0-preview-fa81dffb",
  "@metamask-previews/assets-controllers": "95.3.0-preview-fa81dffb",
  "@metamask-previews/base-controller": "9.0.0-preview-fa81dffb",
  "@metamask-previews/bridge-controller": "64.5.1-preview-fa81dffb",
  "@metamask-previews/bridge-status-controller": "64.4.3-preview-fa81dffb",
  "@metamask-previews/build-utils": "3.0.4-preview-fa81dffb",
  "@metamask-previews/chain-agnostic-permission": "1.4.0-preview-fa81dffb",
  "@metamask-previews/claims-controller": "0.4.1-preview-fa81dffb",
  "@metamask-previews/composable-controller": "12.0.0-preview-fa81dffb",
  "@metamask-previews/connectivity-controller": "0.1.0-preview-fa81dffb",
  "@metamask-previews/controller-utils": "11.18.0-preview-fa81dffb",
  "@metamask-previews/core-backend": "5.0.0-preview-fa81dffb",
  "@metamask-previews/delegation-controller": "2.0.0-preview-fa81dffb",
  "@metamask-previews/earn-controller": "11.1.0-preview-fa81dffb",
  "@metamask-previews/eip-5792-middleware": "2.1.0-preview-fa81dffb",
  "@metamask-previews/eip-7702-internal-rpc-middleware": "0.1.0-preview-fa81dffb",
  "@metamask-previews/eip1193-permission-middleware": "1.0.3-preview-fa81dffb",
  "@metamask-previews/ens-controller": "19.0.2-preview-fa81dffb",
  "@metamask-previews/error-reporting-service": "3.0.1-preview-fa81dffb",
  "@metamask-previews/eth-block-tracker": "15.0.1-preview-fa81dffb",
  "@metamask-previews/eth-json-rpc-middleware": "23.0.0-preview-fa81dffb",
  "@metamask-previews/eth-json-rpc-provider": "6.0.0-preview-fa81dffb",
  "@metamask-previews/foundryup": "1.0.1-preview-fa81dffb",
  "@metamask-previews/gas-fee-controller": "26.0.2-preview-fa81dffb",
  "@metamask-previews/gator-permissions-controller": "1.0.0-preview-fa81dffb",
  "@metamask-previews/json-rpc-engine": "10.2.1-preview-fa81dffb",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.8-preview-fa81dffb",
  "@metamask-previews/keyring-controller": "25.0.0-preview-fa81dffb",
  "@metamask-previews/logging-controller": "7.0.1-preview-fa81dffb",
  "@metamask-previews/message-manager": "14.1.0-preview-fa81dffb",
  "@metamask-previews/messenger": "0.3.0-preview-fa81dffb",
  "@metamask-previews/multichain-account-service": "5.0.0-preview-fa81dffb",
  "@metamask-previews/multichain-api-middleware": "1.2.6-preview-fa81dffb",
  "@metamask-previews/multichain-network-controller": "3.0.2-preview-fa81dffb",
  "@metamask-previews/multichain-transactions-controller": "7.0.0-preview-fa81dffb",
  "@metamask-previews/name-controller": "9.0.0-preview-fa81dffb",
  "@metamask-previews/network-controller": "29.0.0-preview-fa81dffb",
  "@metamask-previews/network-enablement-controller": "4.1.0-preview-fa81dffb",
  "@metamask-previews/notification-services-controller": "21.0.0-preview-fa81dffb",
  "@metamask-previews/permission-controller": "12.2.0-preview-fa81dffb",
  "@metamask-previews/permission-log-controller": "5.0.0-preview-fa81dffb",
  "@metamask-previews/phishing-controller": "16.1.0-preview-fa81dffb",
  "@metamask-previews/polling-controller": "16.0.2-preview-fa81dffb",
  "@metamask-previews/preferences-controller": "22.0.0-preview-fa81dffb",
  "@metamask-previews/profile-metrics-controller": "2.0.0-preview-fa81dffb",
  "@metamask-previews/profile-sync-controller": "27.0.0-preview-fa81dffb",
  "@metamask-previews/ramps-controller": "3.0.0-preview-fa81dffb",
  "@metamask-previews/rate-limit-controller": "7.0.0-preview-fa81dffb",
  "@metamask-previews/remote-feature-flag-controller": "4.0.0-preview-fa81dffb",
  "@metamask-previews/sample-controllers": "4.0.2-preview-fa81dffb",
  "@metamask-previews/seedless-onboarding-controller": "7.1.0-preview-fa81dffb",
  "@metamask-previews/selected-network-controller": "26.0.2-preview-fa81dffb",
  "@metamask-previews/shield-controller": "5.0.0-preview-fa81dffb",
  "@metamask-previews/signature-controller": "39.0.1-preview-fa81dffb",
  "@metamask-previews/storage-service": "0.0.1-preview-fa81dffb",
  "@metamask-previews/subscription-controller": "5.4.0-preview-fa81dffb",
  "@metamask-previews/token-search-discovery-controller": "4.0.0-preview-fa81dffb",
  "@metamask-previews/transaction-controller": "62.9.2-preview-fa81dffb",
  "@metamask-previews/transaction-pay-controller": "11.0.2-preview-fa81dffb",
  "@metamask-previews/user-operation-controller": "41.0.2-preview-fa81dffb"
}

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.

Hey @NicolasMassart, sorry for the late review, I had some questions/comments below.


if (
response.status === DataDeleteResponseStatus.Success &&
response.regulateId &&
Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to be validating the response data. Is there a reason why we are doing that here? Ideally, the service should return data that is usable, and if not, should throw an error.

…sController and streamline analytics ID handling

- Eliminated the dependency on `@metamask/analytics-controller` from the `AnalyticsPrivacyController` and its tests.
- Updated the `AnalyticsPrivacyController` to accept an `analyticsId` directly, improving clarity and reducing coupling.
- Adjusted tests to reflect the removal of the `AnalyticsController:getState` action, ensuring they now validate the presence of a valid `analyticsId`.
- Cleaned up related code to enhance maintainability and readability.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.


if (!this.state.deleteRegulationId) {
return status;
}
Copy link

Choose a reason for hiding this comment

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

Early return ignores actual hasCollectedDataSinceDeletionRequest state value

Medium Severity

The checkDataDeleteStatus method initializes hasCollectedDataSinceDeletionRequest to false in the status object and returns early when deleteRegulationId is null, without reading the actual state value. This means if data has been collected (via updateDataRecordingFlag(true)) but no deletion request has been made yet, the method incorrectly reports hasCollectedDataSinceDeletionRequest: false instead of true. For GDPR/CCPA compliance tracking, this could lead users to incorrectly believe no data has been collected.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs dev review

Development

Successfully merging this pull request may close these issues.

feat: create analytics data deletion controller

3 participants