Skip to content

chore(analytics): delete legacy analytics symbols (useMetrics, MetaMetrics, MetricsEventBuilder) and remove saveDataRecording chain#31256

Open
NicolasMassart wants to merge 12 commits into
mainfrom
analytics/pr8-deletion
Open

chore(analytics): delete legacy analytics symbols (useMetrics, MetaMetrics, MetricsEventBuilder) and remove saveDataRecording chain#31256
NicolasMassart wants to merge 12 commits into
mainfrom
analytics/pr8-deletion

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

The final deletion step of the analytics migration. Removes all legacy analytics symbols that are no longer referenced (PRs #31249#31255 remove the last consumers).

⚠️ Merge order: This PR must be merged after PRs #31249#31255 (the owner-based consumer migrations). CI will show expected failures until those PRs land on main.

Deleted files:

  • app/components/hooks/useMetrics/ (hook + HOC + types)
  • app/core/Analytics/MetaMetrics.ts + test
  • app/core/Analytics/MetricsEventBuilder.ts + test
  • app/core/Analytics/MetaMetricsTestUtils.ts + test
  • app/components/hooks/useAnalytics/withAnalyticsAwareness.tsx + types + test (superseded by the hook directly)

Modified:

  • MetaMetrics.types.ts — converted to a re-export barrel (data-deletion types stay local)
  • app/core/Analytics/index.ts — removes MetaMetrics class export
  • useAnalytics.ts / useAnalytics.types.ts — removes addTraitsToUser field

Removes the saveDataRecording/dataRecorded chain (F.1):
The chain (SAVE_DATA_RECORDING_FLAGAppStateEventListeneruseAnalyticsDataDeletionDeleteMetaMetricsData) was redundant. The "Delete MetaMetrics Data" button is disabled while the deletion is in-flight using component state (isDataDeleteStarted), which is already sufficient. Removing this chain eliminates unnecessary AsyncStorage reads on every app-state change.

Also updates: CODEOWNERS, analyticsMock.ts (removes stale addTraitsToUser/isDataRecorded), testSetup.js, and related test mock cleanup.

Changelog

CHANGELOG entry: null

Related issues

Refs: #26686

Manual testing steps

N/A — analytics-only refactor, no behaviour change.

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards.
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable
  • I've documented my code using JSDoc format if applicable
  • I've applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics

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.

Made with Cursor


Note

Medium Risk
Large deletion/refactor across analytics, privacy settings, and app-state tracking; delete-metrics UX now relies on local state and metrics opt-in rather than persisted “data recorded” flags.

Overview
Completes the analytics migration by removing legacy entry points (useMetrics, withMetricsAwareness, withAnalyticsAwareness, MetaMetrics, MetricsEventBuilder, MetaMetricsTestUtils) and slimming useAnalytics to delegate directly to analytics / AnalyticsEventBuilder (drops addTraitsToUser, isDataRecorded, and the trackEvent(..., saveDataRecording) side effects).

Deletes the saveDataRecording / ANALYTICS_DATA_RECORDED pipeline: no more updateDataRecordingFlag on track, no hasCollectedDataSinceDeletionRequest from Segment status checks, and DeleteMetaMetricsData resets local “data tracked since deletion” on successful task creation instead of syncing from storage on mount.

MetaMetrics.types.ts becomes a re-export barrel toward util/analytics; CODEOWNERS and global test mocks are updated accordingly.

Reviewed by Cursor Bugbot for commit 1dea68e. Bugbot is set up for automated code reviews on this repo. Configure here.

@NicolasMassart NicolasMassart self-assigned this Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

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.

@NicolasMassart

Copy link
Copy Markdown
Contributor Author

CI status note

This PR deletes MetricsEventBuilder, MetaMetrics, useMetrics, and related files. CI will fail until PRs #31249, #31250, #31251, #31252, #31253, #31254, #31255 (which migrate the last consumers) are merged to main first.

Merge order: PR1–PR7 → PR8 → PR9

@mm-token-exchange-service mm-token-exchange-service Bot added INVALID-PR-TEMPLATE PR's body doesn't match template and removed INVALID-PR-TEMPLATE PR's body doesn't match template labels Jun 9, 2026
NicolasMassart and others added 6 commits June 9, 2026 16:32
…nterface is updated

Co-authored-by: Cursor <cursoragent@cursor.com>
…entBuilder from actionButtonTracking test

Co-authored-by: Cursor <cursoragent@cursor.com>
…k to match test assertion

Co-authored-by: Cursor <cursoragent@cursor.com>
… removes it from UseAnalyticsHook)

Co-authored-by: Cursor <cursoragent@cursor.com>
…ved from UseAnalyticsHook in PR8)

Co-authored-by: Cursor <cursoragent@cursor.com>
…tionButtonTracking test

The AnalyticsTrackingEvent type still includes saveDataRecording, so the mock
needs to return it to match the assertion added in the previous fix commit.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ypes to fix SonarCloud duplication

MetaMetrics.types.ts was re-declaring the same 36-line block of data deletion
types already defined in analyticsDataDeletion.types.ts, triggering a 3.4%
new_duplicated_lines_density (threshold: 3%). Replace with re-exports.

Co-authored-by: Cursor <cursoragent@cursor.com>
@NicolasMassart NicolasMassart marked this pull request as ready for review June 11, 2026 15:39
@NicolasMassart NicolasMassart requested review from a team as code owners June 11, 2026 15:39
@NicolasMassart NicolasMassart requested a review from a team as a code owner June 11, 2026 15:39
@NicolasMassart NicolasMassart moved this to Needs dev review in PR review queue Jun 11, 2026
@github-actions github-actions Bot added the risk:medium AI analysis: medium risk label Jun 11, 2026
NicolasMassart and others added 2 commits June 12, 2026 10:34
Updated the DeleteMetaMetricsData component to reset the state indicating whether data has been tracked since the last deletion. This change ensures that the UI accurately reflects the current state immediately after a deletion request is initiated, improving user experience and clarity in the security settings section.
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeSwap, SmokeStake, SmokeWalletPlatform, SmokeMoney, SmokePerps, SmokeMultiChainAPI, SmokePredictions, SmokeSeedlessOnboarding, SmokeBrowser, SmokeSnaps
  • Selected Performance tags: @PerformanceAccountList, @PerformanceOnboarding, @PerformanceLogin, @PerformanceSwaps, @PerformanceLaunch, @PerformanceAssetLoading, @PerformancePredict, @PerformancePreps
  • Risk Level: high
  • AI Confidence: 100%
click to see 🤖 AI reasoning details

E2E Test Selection:
Hard rule (global-infrastructure-change): Global infrastructure changed: app/components/hooks/useAnalytics/useAnalytics.test.tsx, app/components/hooks/useAnalytics/useAnalytics.ts, app/components/hooks/useAnalytics/useAnalytics.types.ts, app/components/hooks/useAnalytics/withAnalyticsAwareness.test.tsx, app/components/hooks/useAnalytics/withAnalyticsAwareness.tsx, app/components/hooks/useAnalytics/withAnalyticsAwareness.types.ts, app/components/hooks/useAnalyticsDataDeletion/useAnalyticsDataDeletion.test.ts, app/components/hooks/useAnalyticsDataDeletion/useAnalyticsDataDeletion.ts, app/components/hooks/useAnalyticsDataDeletion/useAnalyticsDataDeletion.types.ts, app/components/hooks/useMetrics/index.ts, app/components/hooks/useMetrics/useMetrics.test.tsx, app/components/hooks/useMetrics/useMetrics.ts, app/components/hooks/useMetrics/useMetrics.types.ts, app/components/hooks/useMetrics/withMetricsAwareness.test.tsx, app/components/hooks/useMetrics/withMetricsAwareness.tsx, app/components/hooks/useMetrics/withMetricsAwareness.types.ts, app/store/sagas/backfillSocialLoginMarketingConsent.test.ts, app/store/sagas/backfillSocialLoginMarketingConsent.ts, app/store/sagas/sagas.test.ts. Running all tests.

Performance Test Selection:
Fallback: AI analysis did not complete successfully. Running all performance tests.

View GitHub Actions results

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Performance Test Results

ℹ️ Performance test results are currently non-blocking and will not block this PR.

All tests passed · 19 tests · 1 device

📱 Devices tested (1)

Android: Google Pixel 8 Pro (v14.0)

✅ Passed Tests (19)
Test Platform Device Duration Team Recording
Asset View, SRP 1 + SRP 2 + SRP 3 Android Google Pixel 8 Pro (v14.0) 1.35s @assets-dev-team 📹 Watch
Aggregated Balance Loading Time, SRP 1 + SRP 2 + SRP 3 Android Google Pixel 8 Pro (v14.0) 8.63s @assets-dev-team 📹 Watch
Cross-chain swap flow - ETH to SOL - 50+ accounts, SRP 1 + SRP 2 + SRP 3 Android Google Pixel 8 Pro (v14.0) 6.44s @swap-bridge-dev-team 📹 Watch
Cold Start: Measure ColdStart To Login Screen Android Google Pixel 8 Pro (v14.0) 3.57s @metamask-mobile-platform 📹 Watch
Swap flow - ETH to LINK, SRP 1 + SRP 2 + SRP 3 Android Google Pixel 8 Pro (v14.0) 3.01s @swap-bridge-dev-team 📹 Watch
Measure Warm Start: Login To Wallet Screen Android Google Pixel 8 Pro (v14.0) 0.82s @metamask-mobile-platform 📹 Watch
Measure Warm Start: Warm Start to Login Screen Android Google Pixel 8 Pro (v14.0) 1.10s @metamask-mobile-platform 📹 Watch
Perps add funds Android Google Pixel 8 Pro (v14.0) 7.98s @mm-perps-engineering-team 📹 Watch
Predict Available Balance - Complete Flow Performance Android Google Pixel 8 Pro (v14.0) 0.89s @team-predict 📹 Watch
Predict Market Details - Complete Flow Performance Android Google Pixel 8 Pro (v14.0) 6.58s @team-predict 📹 Watch
Predict Deposit - Complete Flow Performance Android Google Pixel 8 Pro (v14.0) 13.82s @team-predict 📹 Watch
Connect to Uniswap dapp, edit accounts, choose another account, and skip Solana popup Android Google Pixel 8 Pro (v14.0) 19.41s @metamask-mobile-platform 📹 Watch
Measure Cold Start To Onboarding Screen Android Google Pixel 8 Pro (v14.0) 3.49s @metamask-mobile-platform 📹 Watch
Onboarding Import SRP with +50 accounts, SRP 3 Android Google Pixel 8 Pro (v14.0) 5.69s @metamask-onboarding-team 📹 Watch
Account creation after fresh install Android Google Pixel 8 Pro (v14.0) 3.81s @metamask-onboarding-team 📹 Watch
Cold Start after importing a wallet Android Google Pixel 8 Pro (v14.0) 0.75s @metamask-mobile-platform 📹 Watch
Seedless Onboarding: Apple Login New User Android Google Pixel 8 Pro (v14.0) 12.05s @metamask-onboarding-team 📹 Watch
Perps open position and close it Android Google Pixel 8 Pro (v14.0) 17.40s @mm-perps-engineering-team 📹 Watch
Seedless Onboarding: Google Login New User Android Google Pixel 8 Pro (v14.0) 10.69s @metamask-onboarding-team 📹 Watch

Branch: analytics/pr8-deletion · Build: Normal · Commit: 1b2d6dc · View full run

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

Labels

risk:medium AI analysis: medium risk size-XL team-mobile-platform Mobile Platform team

Projects

Status: Needs dev review

Development

Successfully merging this pull request may close these issues.

1 participant