refactor(analytics): migrate swaps and bridge events#43891
Conversation
|
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. |
✨ Files requiring CODEOWNER review ✨🔑 @MetaMask/accounts-engineers (1 files, +9 -9)
🔄 @MetaMask/swaps-engineers (17 files, +274 -197)
|
Builds ready [6e1b93c]
⚡ Performance Benchmarks (Total: 🟢 12 pass · 🟡 11 warn · 🔴 1 fail)
Bundle size diffs
|
6e1b93c to
d9dc238
Compare
Builds ready [d9dc238]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs
|
d9dc238 to
3beecd0
Compare
3beecd0 to
d4c62a7
Compare
d4c62a7 to
7b1b6e5
Compare
7b1b6e5 to
f462627
Compare
f462627 to
1efcce6
Compare
Builds ready [1efcce6] [reused from 3beecd0]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 4 warn · 🔴 0 fail)
Bundle sizes
|
1efcce6 to
258aa79
Compare
258aa79 to
87fccac
Compare
87fccac to
4884487
Compare
Builds ready [8b7f549]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [96c9a55]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [9ba3a65]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 10 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Set SupportLinkClicked properties.location from segment page title instead of omitting or hardcoding it. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [1c75a4f]
⚡ Performance Benchmarks (Total: 🟢 13 pass · 🟡 8 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Align useHardwareWalletMetrics with the migrated track helper that expects AnalyticsEvent payloads, fixing test lint TypeScript failures on the branch. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [291bce1]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 8 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Remove redundant bridge init analytics test, restore openBlockExplorer usage with a useAnalytics adapter, revert console baseline ratchets, and mock analytics/background in tests instead of tolerating console noise. Co-authored-by: Cursor <cursoragent@cursor.com>
Remove duplicate bridge CTA mock, mock useAnalytics in hardware wallet metrics and confirm footer tests after useHardwareWalletMetrics migration. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [5fbc31c]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 7 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Keep useAnalytics mock in useHardwareWalletMetrics test after merging latest main. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates swaps- and bridge-related analytics instrumentation from legacy MetaMetrics trackEvent payloads (and MetaMetricsContext) to the newer createEventBuilder(...) + trackEvent(...) flow via useAnalytics() in the UI and app/scripts/controllers/analytics in the background, as part of the umbrella analytics migration (#43885).
Changes:
- Replaced UI MetaMetricsContext usage with
useAnalytics()and converted event payloads tocreateEventBuilder(...).addCategory(...).addProperties(...).addSensitiveProperties(...).build(). - Updated background bridge controller initialization to emit analytics via
controllers/analyticsinstead of messenger-callingMetaMetricsController:trackEvent. - Adjusted unit tests to mock
useAnalytics()and assert against the new built-event shape.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/pages/swaps/view-on-block-explorer/view-on-block-explorer.js | Migrates external-link click tracking to useAnalytics() + event builder. |
| ui/pages/swaps/view-on-block-explorer/view-on-block-explorer.test.js | Mocks useAnalytics() for the migrated ViewOnBlockExplorer component. |
| ui/pages/swaps/smart-transaction-status/smart-transaction-status.js | Migrates “STX status page loaded” and “Cancel STX” tracking to event builder. |
| ui/pages/swaps/smart-transaction-status/smart-transaction-status.test.js | Mocks useAnalytics() for SmartTransactionStatus coverage. |
| ui/pages/swaps/loading-swaps-quotes/loading-swaps-quotes.js | Migrates “Quotes Request Cancelled” tracking to event builder. |
| ui/pages/swaps/fee-card/fee-card.js | Migrates “Gas Fees: Learn More” link click tracking to event builder. |
| ui/pages/swaps/create-new-swap/create-new-swap.js | Migrates “Make Another Swap” tracking to event builder. |
| ui/pages/swaps/create-new-swap/create-new-swap.test.js | Mocks useAnalytics() and uses a stable trackEvent spy for assertions. |
| ui/pages/swaps/awaiting-swap/awaiting-swap.js | Migrates support-link click + “Quotes Timed Out” tracking; switches to useAnalytics()/useSegmentContext(). |
| ui/pages/swaps/awaiting-swap/awaiting-swap.test.js | Mocks useAnalytics() for AwaitingSwap. |
| ui/pages/swaps/awaiting-signatures/awaiting-signatures.js | Migrates “Awaiting Signature(s) on a HW wallet” tracking to event builder. |
| ui/pages/swaps/awaiting-signatures/awaiting-signatures.test.js | Mocks useAnalytics() for AwaitingSignatures. |
| ui/ducks/swaps/swaps.js | Migrates swap quote lifecycle events (requested/received/no quotes, etc.) to use event builder. |
| ui/pages/bridge/transaction-details/transaction-details.tsx | Migrates support-link tracking to useAnalytics() + useSegmentContext(). |
| ui/pages/bridge/transaction-details/bridge-explorer-links.tsx | Adds adapter to route legacy openBlockExplorer tracking through the new analytics API. |
| ui/pages/bridge/token-insights-modal/token-insights-modal.tsx | Migrates “modal opened” and “contract address copied” tracking to event builder. |
| ui/pages/bridge/token-insights-modal/token-insights-modal.test.tsx | Switches to mocking useAnalytics() and asserts against built-event structure. |
| ui/pages/bridge/prepare/bridge-cta-button.tsx | Switches hardware-wallet recovery CTA tracking to use useAnalytics()-provided trackEvent. |
| ui/pages/bridge/prepare/bridge-cta-button.test.tsx | Updates useAnalytics() mocking and background connection mocking for the migrated CTA flow. |
| ui/pages/bridge/awaiting-signatures/awaiting-signatures.tsx | Migrates “Awaiting Signature(s) on a HW wallet” tracking to event builder. |
| ui/helpers/utils/track-hardware-wallet-recovery-connect-cta-clicked.ts | Refactors hardware wallet recovery CTA tracking to build AnalyticsEvent via event builder and call new trackEvent. |
| ui/helpers/utils/track-hardware-wallet-recovery-connect-cta-clicked.test.ts | Updates assertions to match built-event shape (name, properties.category, etc.). |
| ui/contexts/hardware-wallets/useHardwareWalletMetrics.ts | Switches from MetaMetricsContext to useAnalytics() for recovery CTA tracking hook. |
| ui/contexts/hardware-wallets/useHardwareWalletMetrics.test.tsx | Updates hook test to mock useAnalytics() instead of wrapping MetaMetricsContext provider. |
| ui/pages/confirmations/components/confirm/footer/footer.test.tsx | Updates ConfirmFooter tests to mock useAnalytics() and wire track-event spy into recovery CTA helper. |
| ui/components/app/multichain-bridge-transaction-details-modal/multichain-bridge-transaction-details-modal.tsx | Migrates explorer-link click tracking to useAnalytics() + event builder. |
| app/scripts/messenger-client-init/messengers/bridge-controller-messenger.ts | Removes init-messenger delegation for legacy MetaMetrics trackEvent call. |
| app/scripts/messenger-client-init/bridge-controller-init.ts | Migrates bridge controller background analytics to controllers/analytics trackEvent + createEventBuilder. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Guard optional MetaMetricsEventPayload.category before addCategory and replace Proxy background-connection mock with explicit method stubs. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [c616ca0]
⚡ Performance Benchmarks (Total: 🟢 14 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [c616ca0]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
ccharly
left a comment
There was a problem hiding this comment.
LGTM for accounts:
ui/contexts/hardware-wallets/useHardwareWalletMetrics.test.tsx
ui/contexts/hardware-wallets/useHardwareWalletMetrics.ts
Resolve bridge-explorer-links conflict by passing trackEvent and createEventBuilder directly to openBlockExplorer. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [5ac83c5]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Resolve conflicts in bridge-explorer-links, hardware wallet metrics, bridge-cta-button tests, and footer tests. Restore missing trackHardwareWalletRecoveryConnectCtaClicked import and align openBlockExplorer with trackEvent/createEventBuilder signature. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Builds ready [1313a44]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 6 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.
Files in this PR: 37
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 many analytics payloads across swaps/bridge user flows; behavior should be equivalent but regressions in event names, sensitive properties, or page context would affect metrics only.
Overview
Swaps and bridge analytics move off legacy
MetaMetricsContext/ messengerMetaMetricsController:trackEventontocreateEventBuilder+trackEventviauseAnalytics()in UI andapp/scripts/controllers/analyticsin background bridge init.Bridge background: Unified swap/bridge events no longer go through
initMessenger.call('MetaMetricsController:trackEvent', …); bridge init messenger drops MetaMetrics delegation and the unusedinitMessengerparameter.UI (swaps, bridge, multichain bridge modal): Quote, swap lifecycle, hardware-wallet awaiting signatures, block explorer / support links, token insights, STX status, and related flows build events with the builder (categories, properties, sensitive properties,
environmentTypewhere needed). Support-link clicks setlocationfromuseSegmentContext().page?.titleinstead of mergingMetaMetricsContextProp.PageTitle.Tests: Mocks and expectations updated for
useAnalyticsand built event shape (e.g.name+ mergedproperties.category).Reviewed by Cursor Bugbot for commit 1313a44. Bugbot is set up for automated code reviews on this repo. Configure here.