-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
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) anduseAnalyticsDataDeletion(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. Noinit(): values currently loaded in MetaMetricsconfigure()(regulation id, date, data-recorded flag) are lazy-loaded from StorageWrapper when the deletion functions are first called. Extract from MetaMetrics: Segment API viafetch(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; removeuseMetrics(). - Authentication.ts:
deleteUser()callsanalyticsDataDeletion.createDataDeletionTask(). - MetaMetrics: remove data-deletion state and the six methods;
configure()no-op or removed; trimIMetaMetricsand MetaMetrics tests. - Tests: mock
analyticsDataDeletionin 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.tsanduseAnalyticsDataDeletionexist 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.