refactor(analytics): PR A0 add identify() as backward-compat alias for addTraitsToUser() in useAnalytics#26807
Conversation
…() in useAnalytics Adds `identify()` as the canonical method name in UseAnalyticsHook and its implementation, keeping `addTraitsToUser` as a deprecated alias. No consumers are touched — this unblocks Phase C/D/F PRs to rename consumers incrementally. useMetrics and MetaMetrics are intentionally not modified: those files will be deleted once all consumers have migrated. Refs: #26686
|
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. |
1cd0b7f
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
No E2E tests are required because:
Performance Test Selection: |
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.
| }, | ||
| identify: async (userTraits: AnalyticsUserTraits): Promise<void> => { | ||
| analytics.identify(userTraits); | ||
| }, |
There was a problem hiding this comment.
Missing await in new identify method
Medium Severity
The new identify method is declared async and returns Promise<void>, but the inner analytics.identify(userTraits) call is not awaited. If analytics.identify() returns a rejected promise, that rejection is silently swallowed — callers awaiting identify() would receive a resolved promise and never learn the operation failed. The sibling enable method in the same object correctly uses await for its async calls (await analytics.optOut() / await analytics.optIn()), so this appears to be an oversight. The existing addTraitsToUser has the same flaw, but since identify is the new canonical method intended to replace it, propagating errors correctly here matters.
|





Description
Part of the analytics cleanup workstream (#26686).
Adds
identify()as the canonical method name toUseAnalyticsHookand its implementation, keepingaddTraitsToUseras a@deprecatedalias. No consumers are touched — this purely extends theuseAnalyticsinterface to unblock Phase C/D/F PRs renaming consumers incrementally without breaking changes.useMetricsandMetaMetricsfiles are intentionally not modified as they are deleted once all consumers have migrated.Changelog
CHANGELOG entry: null
Related issues
Refs: #26808
Manual testing steps
Screenshots/Recordings
Before
N/A — no UI changes.
After
N/A — no UI changes.
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Runtime change is additive and backward-compatible (new
identify()plus deprecatedaddTraitsToUser()alias). Most touched files are unit tests and test setup, so risk is mainly around test stability rather than app behavior.Overview
Adds
identify()touseAnalyticsas the canonical user-traits API, while keepingaddTraitsToUser()as a deprecated alias; updates the hook type, implementation, and unit tests to cover both entry points.Refactors analytics mocking across the test suite by introducing
createMockUseAnalyticsHook()inanalyticsMock.tsand updating many component tests plustestSetup.js/useAnalyticsJest mocks to use this factory instead of bespoke inline mock objects.Written by Cursor Bugbot for commit 4da4d00. This will update automatically on new commits. Configure here.