feat: create new useAnalytics hook to replace useMetrics#25045
feat: create new useAnalytics hook to replace useMetrics#25045NicolasMassart merged 13 commits intomainfrom
Conversation
Co-authored-by: nicolas.massart <nicolas.massart@consensys.net>
Co-authored-by: nicolas.massart <nicolas.massart@consensys.net>
- Remove legacy type support (ITrackingEvent, UserTraits, IMetaMetricsEvent) - Accept only AnalyticsTrackingEvent and AnalyticsUserTraits - Rename getMetaMetricsId to getAnalyticsId - Rename interface IUseAnalyticsHook to UseAnalyticsHook (remove I prefix) - Remove type cast from addTraitsToUser - Update createEventBuilder to only accept string | AnalyticsTrackingEvent
|
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. |
…k-mobile into feat/new_analytics_hook
…k-mobile into feat/new_analytics_hook
…ve hook implementation - Refactored the `useAnalytics` hook to use instance methods of `MetaMetrics` directly, enhancing clarity and maintainability. - Updated tests to mock `MetaMetrics` methods more effectively, ensuring accurate tracking of analytics events. - Improved test structure by resetting mocks after each test to prevent state leakage. - Adjusted mock return values for better alignment with expected outcomes in tests.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThis PR introduces a new
The new hook is already being imported by Ramp components, but this PR appears to be establishing the hook infrastructure and test mocks. Since the changes are additive, don't modify existing behavior, and don't touch E2E test infrastructure, no E2E tags are required. |
|
|
Missing release label release-7.64.0 on PR. Adding release label release-7.64.0 on PR and removing other release labels(release-7.65.0), as PR was added to branch 7.64.0 when release was cut. |

Description
This PR creates the
useAnalyticshook to exclusively use the new analytics types, targetting future full removal of all legacy type support. This is part of the ongoing migration away from MetaMetrics internals to the new analytics system.Changes:
useAnalyticshook that exclusively uses new analytics types (AnalyticsTrackingEventandAnalyticsUserTraits)withAnalyticsAwarenessHOC that injects theuseAnalyticshook into component propsuseMetricsandwithMetricsAwarenesspointing to new implementationsuseAnalyticsandwithAnalyticsAwarenessin test setupReason for change:
This simplifies the hook API and forces migration to the new analytics types, reducing technical debt and ensuring all consumers use the modern analytics system.
Improvement:
Changelog
CHANGELOG entry: null
Related issues
Fixes: #25036
Manual testing steps
N/A
Screenshots/Recordings
N/A
Before
N/A
After
N/A
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduces a new analytics hook and HOC aligned with the modern analytics system while keeping data deletion behavior via MetaMetrics during migration.
useAnalyticshook usingAnalyticsEventBuilderandanalyticshelper: supportstrackEvent,enable(opt-in/out),identifyviaaddTraitsToUser,isEnabled,getAnalyticsId; delegates data deletion APIs (createDataDeletionTask,checkDataDeleteStatus, dates/IDs,isDataRecorded) toMetaMetricsand updates the recording flagwithAnalyticsAwarenessHOC to injectmetricsfromuseAnalyticsuseMetricsandwithMetricsAwarenesswith JSDoc notices and minimal tweaks in exports/docsuseAnalyticsand the HOC; extend global test mocks intestSetup.jsfor the new hook/HOCWritten by Cursor Bugbot for commit d9260b0. This will update automatically on new commits. Configure here.