refactor(analytics): D2 migrate useMetrics to useAnalytics in Stake and Earn components#28263
Conversation
Replace all useMetrics usages in the Rewards module with useAnalytics, import MetaMetricsEvents from core/Analytics instead of hooks/useMetrics, and add createMockEventBuilder factory to analyticsMock to eliminate inline builder boilerplate across test files.
|
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. |
Add standardized useAnalytics hook mocks in ClaimBanner, StakingCta, and UnstakeTimeCard tests so migrated analytics lines are exercised and new-code coverage aligns with the useMetrics->useAnalytics refactor.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
… refactor/26686_d2-earn_use-analytics-migration
Matt561
left a comment
There was a problem hiding this comment.
Approving for Earn-owned files.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Key findings:
The staking flows (stake, unstake, claim) are covered by SmokeTrade (ETH staking flows). The StakeConfirmationView and UnstakeConfirmationView are confirmation screens, so SmokeConfirmations is also warranted per the tag dependency rules (SmokeTrade → SmokeConfirmations). Risk is low because this is a pure refactoring with no behavioral changes, but we should validate the staking flows still work correctly with the new analytics hook. Performance Test Selection: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #28263 +/- ##
==========================================
- Coverage 82.16% 82.16% -0.01%
==========================================
Files 4924 4927 +3
Lines 129321 129398 +77
Branches 28821 28833 +12
==========================================
+ Hits 106256 106317 +61
- Misses 15791 15808 +17
+ Partials 7274 7273 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
✅ E2E Fixture Validation — Schema is up to date |




Important
Depends on D1 #28262 for createMockEventBuilder added in
app/util/test/analyticsMock.ts.if D1 revert is ever needed, you have to also revert this one
Description
Part of the analytics system migration from the legacy
useMetricshook to the newuseAnalyticshook across Stake and Earn components.What changed:
useMetricswithuseAnalyticsin 8 production components:GasImpactModal,ClaimBanner,StakingCta,FooterButtonGroup,RewardsCard,UnstakeTimeCard, and related views (StakeConfirmationView,UnstakeConfirmationView).MetaMetricsEventsimports fromhooks/useMetricstocore/Analytics(the canonical source) in all affected files.MetricsEventBuilder.createEventBuilderwithAnalyticsEventBuilder.createEventBuilderintooltipMetaMetricsUtils.ts.createMockUseAnalyticsHookfactory +jest.mocked(useAnalytics)pattern instead of manual inline mock objects, reducing boilerplate and improving type safety.Changelog
CHANGELOG entry: null
Related issues
Fixes: #26817
Manual testing steps
N/A
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Moderate risk because it changes analytics instrumentation in staking/earn user flows; functional behavior should be unchanged but event building/tracking could regress or break silently.
Overview
Migrates Stake/Earn UI analytics from the legacy
useMetricshook to the neweruseAnalyticshook across staking modals/cards/confirmation flows, and standardizesMetaMetricsEventsimports to come fromcore/Analytics.Updates tooltip event construction to use
AnalyticsEventBuilderinstead ofMetricsEventBuilder, and refactors affected unit tests to mockuseAnalyticsvia shared helpers (createMockUseAnalyticsHook/createMockEventBuilder) to avoid async Engine readiness polling and reduce inline mock boilerplate.Reviewed by Cursor Bugbot for commit ca3af27. Bugbot is set up for automated code reviews on this repo. Configure here.