refactor(analytics): migrate shield and subscription events#43893
Conversation
✨ Files requiring CODEOWNER review ✨🔐 @MetaMask/web3auth (4 files, +82 -32)
|
Builds ready [94860b3]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 8 warn · 🔴 1 fail)
Bundle size diffs
|
94860b3 to
83133e5
Compare
Builds ready [83133e5]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs
|
|
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. |
83133e5 to
fb88c75
Compare
fb88c75 to
7d1a8e9
Compare
7d1a8e9 to
336865d
Compare
336865d to
11e8114
Compare
11e8114 to
af195c9
Compare
af195c9 to
00dd119
Compare
00dd119 to
3ec56e4
Compare
3ec56e4 to
97df82c
Compare
Limit scope to analytics migration bucket files only. Part of analytics migration umbrella PR #43885.
83da1f6 to
59586b7
Compare
Builds ready [59586b7]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs
|
Clarify oauth init test mocks for MetaMetrics vs Analytics controllers and inline subscription service Shield event tracking calls. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [baf3060]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Pull request overview
This PR is a Shield/Subscription domain sub-step of the analytics migration umbrella (#43885), moving UI and background MetaMetrics trackEvent call sites to the new createEventBuilder(...).build() event shape and routing events via useAnalytics() (UI) or app/scripts/controllers/analytics (background).
Changes:
- Updated Shield/Subscription UI tracking to build events with
createEventBuilderand send them throughuseAnalytics().trackEvent. - Updated background Shield/Subscription tracking to use
createEventBuilder+trackEventfromapp/scripts/controllers/analyticsinstead ofMetaMetricsController:trackEventmessenger calls. - Adjusted and expanded unit tests/mocks to align with the new analytics APIs and event payload shape.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/pages/shield/transaction-shield/transaction-shield.test.tsx | Updates router/analytics mocks to support new analytics hook usage. |
| ui/pages/shield/transaction-shield/manage-shield-plan/manage-shield-plan.test.tsx | Adds useAnalytics mocking to keep tests isolated from analytics implementation. |
| ui/hooks/shield/metrics/useSubscriptionMetrics.ts | Refactors Shield subscription metric emitters to use useAnalytics + event builder (centralizing common props). |
| ui/components/app/modals/visit-support-data-consent-modal/visit-support-data.test.tsx | Updates expectations and mocks to validate new built-event payload shape. |
| ui/components/app/modals/visit-support-data-consent-modal/visit-support-data-consent-modal.tsx | Migrates support-link click tracking to useAnalytics + builder and includes page title via segment context. |
| ui/components/app/modals/add-funds-modal/add-funds-modal.tsx | Migrates navigation metrics in the modal to event builder + useAnalytics. |
| ui/components/app/modals/add-funds-modal/add-funds-modal.test.tsx | Adds useAnalytics mocking for the new tracking implementation. |
| app/scripts/services/subscription/subscription-service.ts | Migrates Shield-related background tracking to controllers/analytics helpers. |
| app/scripts/services/subscription/subscription-service.test.ts | Updates test wiring/mocks to remove reliance on MetaMetricsController:trackEvent. |
| app/scripts/services/oauth/types.ts | Removes trackEvent from OAuth service options surface (no longer injected). |
| app/scripts/services/oauth/oauth-service.ts | Migrates buffered tracking path to accept built analytics events and routes via analytics helpers / buffering API. |
| app/scripts/services/oauth/oauth-service.test.ts | Updates tests to reflect constructor signature change and new analytics helper mocking. |
| app/scripts/messenger-client-init/seedless-onboarding/oauth-service-init.ts | Stops injecting trackEvent into OAuth service init (now uses analytics helpers directly). |
| app/scripts/messenger-client-init/seedless-onboarding/oauth-service-init.test.ts | Updates controller mocks to reflect split MetaMetrics onboarding vs Analytics opt-in state. |
| app/scripts/messenger-client-init/messengers/subscription/subscription-service-messenger.ts | Removes now-unused MetaMetricsController:trackEvent permission from subscription service messenger. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Remove redundant omitBy filtering in trackShieldEvent since createEventBuilder.addProperties already strips undefined values, and mock useLocation.search as an empty string in TransactionShield tests. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Builds ready [e77a542]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|


Description
Sub-PR of umbrella tracker #43885.
Migrates MetaMetrics
trackEventcall sites in this CODEOWNERS domain tocreateEventBuilder+trackEventviauseAnalytics()(UI) orapp/scripts/controllers/analytics(background).Dependency note: Can merge in parallel with other domain PRs after PR1.
Files in this PR: 21
Changelog
CHANGELOG entry: null
Related issues
Part of analytics migration umbrella: #43885
Manual testing steps
yarn start.Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches analytics emission across OAuth onboarding failures and Shield subscription flows; behavior should be equivalent but any regression could skew product metrics or drop pre-consent buffered events.
Overview
Migrates Shield, subscription, OAuth, and related UI from legacy
MetaMetricsController:trackEvent/MetaMetricsContexttocreateEventBuilder+trackEvent(app/scripts/controllers/analyticsin background,useAnalytics()in UI).Background:
SubscriptionServicedrops theMetaMetricsController:trackEventmessenger delegate and emits Shield metrics (cohort assignment, subscription requests, payment method changes, rewards opt-in) via the analytics module.OAuthServiceno longer accepts an injectedtrackEvent; social login failure events use the builder API while pre–opt-in buffering still maps built events back toaddEventBeforeMetricsOptInwhen onboarding/opt-in are incomplete.UI: Modals (
AddFundsModal, support data consent) anduseSubscriptionMetricsswitch touseAnalytics, with a sharedtrackShieldEventhelper to reduce duplication. Support link clicks now put page title on the event properties (viauseSegmentContext) instead of the oldcontextPropsIntoEventPropertiesoption.Tests are updated to mock
useAnalytics/controllers/analyticsand to split OAuth init mocks betweenMetaMetricsControllerandAnalyticsControllerfor opt-in state.Reviewed by Cursor Bugbot for commit e77a542. Bugbot is set up for automated code reviews on this repo. Configure here.