Skip to content

refactor: move analytics data deletion out of MetaMetrics (1/4 mobile-platform)#26022

Merged
NicolasMassart merged 6 commits intomainfrom
refactor/25767_Move_analytics_data_deletion_mobile-platform_split_1-4
Feb 13, 2026
Merged

refactor: move analytics data deletion out of MetaMetrics (1/4 mobile-platform)#26022
NicolasMassart merged 6 commits intomainfrom
refactor/25767_Move_analytics_data_deletion_mobile-platform_split_1-4

Conversation

@NicolasMassart
Copy link
Copy Markdown
Contributor

@NicolasMassart NicolasMassart commented Feb 12, 2026

Description

Part 1/4 of #25767Code owner: mobile-platform

This PR extracts analytics data-deletion logic from the MetaMetrics singleton into a dedicated analyticsDataDeletion utility and useAnalyticsDataDeletion React hook.

Why? The MetaMetrics class accumulated responsibilities beyond its core analytics purpose (tracking, flushing, identity). Data deletion (Segment regulation API calls, status polling, StorageWrapper caching) is a distinct concern that belongs in its own module.

What changed:

  • New app/util/analytics/analyticsDataDeletion.ts — pure-function utility owning all deletion state and API calls (previously in MetaMetrics).
  • New app/components/hooks/useAnalyticsDataDeletion/ — React hook exposing createDataDeletionTask, checkDataDeleteStatus, getDeleteRegulationCreationDate, getDeleteRegulationId, isDataRecorded.
  • Updated useMetrics and useAnalytics hooks — delegate deletion methods to the new utility instead of calling MetaMetrics instance methods.
  • Stripped MetaMetrics.ts — removed configure(), all 6 deletion methods, and related private state. Interface updated accordingly.
  • Updated Authentication.ts — calls createDataDeletionTask from the utility instead of via MetaMetrics.
  • Updated sagas/index.ts — removed MetaMetrics.configure() call from startAppServices.
  • Tests — full coverage for the new utility and hook; existing MetaMetrics, Authentication, sagas, useMetrics, and useAnalytics tests updated.

Changelog

CHANGELOG entry: null

Related issues

Fixes: #25767
Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-297

Manual testing steps

Feature: Analytics data deletion

  Scenario: user requests data deletion from Settings
    Given the user is on Settings > Security & Privacy
    When user taps "Delete MetaMetrics data"
    Then a deletion task is created via Segment regulation API
    And the deletion status is reflected in the UI

Screenshots/Recordings

N/A — no UI changes, internal refactor only.

Before

N/A

After

Scenario: user requests data deletion from Settings

No changes

 (NOBRIDGE) INFO  TRACK event saved {"event": "Delete MetaMetrics Data Request Submitted", "properties": {"device_model": "Apple iPhone17,5", "os": "ios", "os_version": "26.2"}, "type": "track"}
 (NOBRIDGE) INFO  Sent 2 events
Untitled

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Touches analytics privacy/data-deletion behavior, including Segment API requests and persisted state/caching, and changes app startup/auth flows that previously invoked MetaMetrics.configure and deletion methods.

Overview
Extracts analytics data-deletion out of MetaMetrics. Adds a new util/analytics/analyticsDataDeletion module (with in-memory caching + fetch calls to Segment regulations endpoints and persistence via StorageWrapper) and a new useAnalyticsDataDeletion hook that exposes the same six deletion/recording helpers.

Updates callers to stop depending on MetaMetrics for deletion/config. useAnalytics/useMetrics now delegate deletion/status + updateDataRecordingFlag to the new util, Authentication.deleteUser triggers deletion via the util, startAppServices no longer calls MetaMetrics.configure, and MetaMetrics/IMetaMetrics are stripped of configure + all data-deletion state/methods. Tests are updated and expanded to cover the new util/hook and the updated integrations.

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

Extract data-deletion logic from MetaMetrics into a dedicated
analyticsDataDeletion util and useAnalyticsDataDeletion hook.
Remove configure() and deletion methods from MetaMetrics class.
@NicolasMassart NicolasMassart requested a review from a team as a code owner February 12, 2026 16:27
@NicolasMassart NicolasMassart self-assigned this Feb 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-mobile-platform Mobile Platform team label Feb 12, 2026
Copy link
Copy Markdown

@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 3 potential issues.

@NicolasMassart NicolasMassart marked this pull request as draft February 12, 2026 17:08
- Introduced a test case to verify that the function returns `hasCollectedDataSinceDeletionRequest` as false when data is recorded but no regulation ID exists.
- Added another test case to ensure a valid status object is returned when storage read throws an error.
- Updated the `checkDataDeleteStatus` function to handle errors during cache loading gracefully, logging the error without interrupting the flow.
- Updated the `setItem` method in `analyticsDataDeletion.ts` to safely handle potential null values by using optional chaining.
- Adjusted the mock implementation of `setItem` in `testSetup.js` to remove the resolved value, aligning with the actual implementation.
@NicolasMassart NicolasMassart marked this pull request as ready for review February 13, 2026 10:24
@NicolasMassart NicolasMassart added the Code Impact - Medium Average task code change that can relatively safely being applied to the codebase label Feb 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeWalletPlatform
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 78%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR is an internal refactoring that extracts analytics data deletion functionality from the MetaMetrics class into a standalone utility module (analyticsDataDeletion.ts). The changes include:

  1. New utility module: app/util/analytics/analyticsDataDeletion.ts - Contains all data deletion related functions (createDataDeletionTask, checkDataDeleteStatus, getDeleteRegulationCreationDate, getDeleteRegulationId, isDataRecorded, updateDataRecordingFlag)

  2. MetaMetrics simplification: Removed data deletion methods and the configure() method from MetaMetrics class

  3. Hook updates: useAnalytics and useMetrics hooks now import from the new utility instead of MetaMetrics. New useAnalyticsDataDeletion hook created.

  4. Authentication service update: Authentication.deleteUser() now uses the new utility directly for data deletion

  5. Sagas update: Removed MetaMetrics.configure() call from app startup

The changes are primarily internal refactoring with no user-facing behavior changes. The analytics data deletion functionality is used in Settings > Security & Privacy and wallet deletion flows. All changes have comprehensive unit test coverage.

Selected SmokeWalletPlatform because:

  • It covers wallet lifecycle analytics tracking for new wallet creation and SRP import events
  • It tests transaction history and activity display which involves analytics
  • The Authentication service changes (deleteUser) affect wallet deletion flows
  • The sagas changes affect app startup services

The risk is medium because while this is a refactoring, it touches core infrastructure (Analytics, Authentication, Sagas) that could have subtle effects if something was missed. However, the comprehensive unit tests and the fact that the API surface remains the same provides confidence.

Performance Test Selection:
This PR is an internal refactoring of analytics data deletion functionality. The changes move code from MetaMetrics class to a standalone utility module without changing the underlying logic or adding new operations. The refactoring doesn't affect UI rendering, data loading patterns, app startup time, or any user-facing performance characteristics. The analytics tracking itself is unchanged - only the internal organization of the code has been modified. No performance tests are needed.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@NicolasMassart NicolasMassart added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit 8b79dda Feb 13, 2026
197 of 200 checks passed
@NicolasMassart NicolasMassart deleted the refactor/25767_Move_analytics_data_deletion_mobile-platform_split_1-4 branch February 13, 2026 15:24
@github-actions github-actions bot locked and limited conversation to collaborators Feb 13, 2026
@metamaskbot metamaskbot added the release-7.67.0 Issue or pull request that will be included in release 7.67.0 label Feb 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Code Impact - Medium Average task code change that can relatively safely being applied to the codebase release-7.67.0 Issue or pull request that will be included in release 7.67.0 size-XL team-mobile-platform Mobile Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Move analytics data deletion out of MetaMetrics into dedicated util and hook

3 participants