refactor(analytics): migrate orphan platform metrics UI events#44378
Conversation
Part of analytics migration umbrella #43885 (15e · Platform metrics UI).
Builds ready [dd0eb16]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 6 warn · 🔴 1 fail)
Bundle sizes
|
|
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. |
Drop useABTest from this PR to avoid changing experiment exposure semantics. Add parity assertions for migrated toggle and deletion events, and make the analytics action mock return a resolved promise. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Builds ready [1e1609b]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 7 warn · 🔴 1 fail)
Bundle sizes
|
There was a problem hiding this comment.
Pull request overview
This PR continues the MetaMetrics → Analytics migration by moving remaining “Platform metrics UI” event tracking call sites from legacy MetaMetricsContext.trackEvent usage to the newer useAnalytics() hook and createEventBuilder API, while updating unit tests and Jest action mocks accordingly.
Changes:
- Migrated UI components to
useAnalytics()+createEventBuilderfor MetaMetrics opt-in/out and data deletion events. - Updated unit tests to mock
useAnalytics()and assert the new built event payload shape. - Extended the Jest actions manual mock to include
trackAnalyticsEventto supportuseAnalytics-driven code paths in tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ui/components/app/metametrics-toggle/metametrics-toggle.tsx | Replaces MetaMetricsContext usage with useAnalytics() and event-builder-based tracking for opt-in/out events. |
| ui/components/app/metametrics-toggle/metametrics-toggle.test.tsx | Adds useAnalytics mocking and asserts the built analytics event payloads for toggle flows. |
| ui/components/app/delete-metametrics-data-button/delete-metametrics-data-button.test.tsx | Mocks useAnalytics() and resets tracking mock state to keep tests isolated from analytics implementation. |
| ui/components/app/clear-metametrics-data/clear-metametrics-data.tsx | Switches data deletion success/error tracking to builder events (including excludeMetaMetricsId options). |
| ui/components/app/clear-metametrics-data/clear-metametrics-data.test.tsx | Adds useAnalytics mocking and validates deletion/error events including options payload. |
| ui/mocks/actions.js | Adds a trackAnalyticsEvent stub to the actions manual mock to support useAnalytics call sites during tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



Description
Migrates remaining legacy
MetaMetricsContext.trackEvent/trackMetaMetricsEventcall sites in the Platform (metametrics toggle, clear data, A/B test hook) domain touseAnalytics()+createEventBuilder(ortrackAnalyticsEventfor Redux thunks).Part of umbrella tracker #43885 (15e · Platform metrics UI).
Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
yarn start).Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Refactor-only analytics instrumentation with tests locking event shape; no changes to metrics opt-in, deletion tasks, or user data handling behavior.
Overview
Platform settings analytics in the clear-metrics modal and participate-in-metrics toggle now go through
useAnalytics()andcreateEventBuilderinstead ofMetaMetricsContext.trackEvent. Event names, categories, properties, and options such asexcludeMetaMetricsIdon deletion flows are unchanged—only the wiring API differs.Tests mock
useAnalyticsand assert the built event payloads for enable/disable toggles, deletion requests, and deletion failures. The shared actions mock adds a no-optrackAnalyticsEventfor Redux/thunk callers.Reviewed by Cursor Bugbot for commit 1e1609b. Bugbot is set up for automated code reviews on this repo. Configure here.