Skip to content

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

@NicolasMassart

Description

@NicolasMassart

Description

What is this about?

Reason for change: MCWP-297 Phase 1-1 (migrate analytics hook test mocks off MetaMetrics; blocked until data deletion is moved out of MetaMetrics).

Extract data deletion (Segment Regulations API + StorageWrapper) from the deprecated MetaMetrics class into a new util and React hook. Goals: remove that logic from MetaMetrics (unblock Batch 1-1 analytics migration), expose useAnalyticsDataDeletion for components and analyticsDataDeletion for non-React code (e.g. Authentication.deleteUser()). Consumers today: Settings “Delete MetaMetrics data”, useAnalytics/useMetrics, Authentication.

Note

The util is a temporary bridge. The new analytics data regulation controller is being developed in MetaMask/core#7643 (Feat: new analytics data regulation controller). Once that lands, useAnalyticsDataDeletion will use the controller directly and the util can be removed or reduced to a thin adapter.


Scenario (for user stories only)

  • GIVEN analytics migration is in progress and data deletion still lives in MetaMetrics
  • WHEN we want to drop MetaMetrics from hooks and tests
  • THEN data deletion is provided by analyticsDataDeletion (util) and useAnalyticsDataDeletion (hook)

Design (for user stories only)

N/A – refactor only; no UI change.


Technical Details (for technical tasks only)

  • Util app/util/analytics/analyticsDataDeletion.ts (temporary until controller exists): plain functions — createDataDeletionTask, checkDataDeleteStatus, getDeleteRegulationCreationDate, getDeleteRegulationId, isDataRecorded, updateDataRecordingFlag. No init(): values currently loaded in MetaMetrics configure() (regulation id, date, data-recorded flag) are lazy-loaded from StorageWrapper when the deletion functions are first called. Extract from MetaMetrics: Segment API via fetch (no axios), analytics.getAnalyticsId() for create.
  • Hook app/components/hooks/useAnalyticsDataDeletion/: returns same API, proxies to util (useMemo for stable refs).
  • useAnalytics / useMetrics: delegate the six data-deletion methods to util; API unchanged.
  • DeleteMetaMetricsData: use useAnalyticsDataDeletion() for deletion, useAnalytics() for trackEvent/createEventBuilder; remove useMetrics().
  • Authentication.ts: deleteUser() calls analyticsDataDeletion.createDataDeletionTask().
  • MetaMetrics: remove data-deletion state and the six methods; configure() no-op or removed; trim IMetaMetrics and MetaMetrics tests.
  • Tests: mock analyticsDataDeletion in useAnalytics/useMetrics tests; add tests for util and hook; fix other tests that mock MetaMetrics data-deletion.

Threat Modeling Framework (for technical tasks only)

  • What are we working on? Extracting data deletion so MetaMetrics can be stripped and migration tests unblocked.
  • What can go wrong? Circular dependency (util → analytics only); wrong mocks.
  • What are we going to do about it? One-way util → analytics; add/update tests and mocks.
  • Did we do a good job? MetaMetrics has no data-deletion code; consumers use util/hook; tests pass with correct mocks.

Acceptance Criteria

  • analyticsDataDeletion.ts and useAnalyticsDataDeletion exist with the six deletion-related exports (no init); state lazy-loaded from StorageWrapper when functions are called; behaviour matches current MetaMetrics data-deletion.
  • useAnalytics/useMetrics delegate to util; DeleteMetaMetricsData uses new hook + useAnalytics; Authentication uses util. Saga no longer calls MetaMetrics.configure() for data-deletion (nothing to replace).
  • MetaMetrics has no data-deletion logic; configure() no-op or removed.
  • Unit tests for util and hook; useAnalytics/useMetrics tests mock util; no new circular deps; existing analytics unchanged.

Stakeholder Review (for MetaMask employees only)

  • Engineering (needed in most cases)
  • Design
  • Product
  • QA (automation tests are required to pass before merging PRs but not all changes are covered by automation tests - please review if QA is needed beyond automation tests)
  • Security
  • Legal
  • Marketing
  • Management (please specify)
  • Other (please specify)

References

  • Reason: MCWP-297 Phase 1-1 — migrate analytics hook test mocks off MetaMetrics.
  • Controller work: MetaMask/core#7643 — Feat: new analytics data regulation controller (@metamask/analytics-data-regulation-controller).
  • Segment: user-deletion, API. Source: app/core/Analytics/MetaMetrics.ts.

Metadata

Metadata

Labels

INVALID-ISSUE-TEMPLATEIssue's body doesn't match any issue template.release-7.67.0Issue or pull request that will be included in release 7.67.0team-mobile-platformMobile Platform team

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions