Skip to content

refactor(analytics): PR A0 add identify() as backward-compat alias for addTraitsToUser() in useAnalytics#26807

Merged
NicolasMassart merged 7 commits into
mainfrom
refactor/26686_a0-platform_identify-alias
Mar 5, 2026
Merged

refactor(analytics): PR A0 add identify() as backward-compat alias for addTraitsToUser() in useAnalytics#26807
NicolasMassart merged 7 commits into
mainfrom
refactor/26686_a0-platform_identify-alias

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Description

Part of the analytics cleanup workstream (#26686).

Adds identify() as the canonical method name to UseAnalyticsHook and its implementation, keeping addTraitsToUser as a @deprecated alias. No consumers are touched — this purely extends the useAnalytics interface to unblock Phase C/D/F PRs renaming consumers incrementally without breaking changes.

useMetrics and MetaMetrics files are intentionally not modified as they are deleted once all consumers have migrated.

Changelog

CHANGELOG entry: null

Related issues

Refs: #26808

Manual testing steps

Feature: analytics cleanup

  Scenario: app builds and tests pass after adding identify alias
    Given the app compiles without TypeScript errors
    When unit tests are run on affected files
    Then all 16 tests pass with no regressions

Screenshots/Recordings

Before

N/A — no UI changes.

After

N/A — no UI changes.

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Low Risk
Runtime change is additive and backward-compatible (new identify() plus deprecated addTraitsToUser() alias). Most touched files are unit tests and test setup, so risk is mainly around test stability rather than app behavior.

Overview
Adds identify() to useAnalytics as the canonical user-traits API, while keeping addTraitsToUser() 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() in analyticsMock.ts and updating many component tests plus testSetup.js/useAnalytics Jest 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.

…() 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
@NicolasMassart NicolasMassart added the team-mobile-platform Mobile Platform team label Mar 2, 2026
@NicolasMassart NicolasMassart self-assigned this Mar 2, 2026
@github-actions

github-actions Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added size-M and removed size-S labels Mar 3, 2026
@NicolasMassart NicolasMassart changed the title refactor: add identify() as backward-compat alias for addTraitsToUser() in useAnalytics refactor(analytics): PR A0 add identify() as backward-compat alias for addTraitsToUser() in useAnalytics Mar 3, 2026
@NicolasMassart NicolasMassart marked this pull request as ready for review March 3, 2026 11:46
@NicolasMassart NicolasMassart requested review from a team as code owners March 3, 2026 11:46
@NicolasMassart NicolasMassart enabled auto-merge March 3, 2026 11:46
@NicolasMassart NicolasMassart moved this to Needs dev review in PR review queue Mar 3, 2026
Brunonascdev
Brunonascdev previously approved these changes Mar 3, 2026
vinnyhoward
vinnyhoward previously approved these changes Mar 3, 2026
jbblanc
jbblanc previously approved these changes Mar 3, 2026
OGPoyraz
OGPoyraz previously approved these changes Mar 4, 2026
shane-t
shane-t previously approved these changes Mar 4, 2026
@NicolasMassart NicolasMassart added this pull request to the merge queue Mar 4, 2026
@github-project-automation github-project-automation Bot moved this from Needs dev review to Review finalised - Ready to be merged in PR review queue Mar 4, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 4, 2026
@github-actions

github-actions Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 95%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR makes minimal changes to the actual app code:

  1. New identify() method in useAnalytics hook: Adds a simple wrapper method that calls analytics.identify(userTraits). This is a non-breaking addition - the existing addTraitsToUser() method is preserved (just marked as deprecated).

  2. Test infrastructure refactoring: Creates a createMockUseAnalyticsHook() factory function in analyticsMock.ts and updates 16 unit test files to use this factory instead of inline mock definitions. This is purely a test code quality improvement.

  3. No changes to feature code: All 22 changed files are either:

    • The analytics hook itself (adding one new method)
    • Test utility files (analyticsMock.ts, testSetup.js)
    • Unit test files (.test.tsx, .test.ts)

No E2E tests are required because:

  • The app code change is backwards compatible (new method, old method still works)
  • No UI components, navigation, or user flows are modified
  • No E2E test infrastructure is affected
  • The unit tests themselves validate the new functionality
  • This is a developer experience improvement for test mocking, not a user-facing change

Performance Test Selection:
No performance tests needed. The changes are: (1) adding a simple wrapper method to the analytics hook that just calls an existing analytics.identify() method, and (2) refactoring unit test mocks. There are no changes to UI rendering, data loading, state management, or any code paths that could impact app performance. The analytics identify() call is a simple pass-through to an existing analytics service method.

View GitHub Actions results

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

@sonarqubecloud

sonarqubecloud Bot commented Mar 5, 2026

Copy link
Copy Markdown

@NicolasMassart NicolasMassart added this pull request to the merge queue Mar 5, 2026
Merged via the queue into main with commit a4a6692 Mar 5, 2026
66 checks passed
@NicolasMassart NicolasMassart deleted the refactor/26686_a0-platform_identify-alias branch March 5, 2026 13:21
@github-project-automation github-project-automation Bot moved this from Review finalised - Ready to be merged to Merged, Closed or Archived in PR review queue Mar 5, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 5, 2026
@metamaskbot metamaskbot added the release-7.69.0 Issue or pull request that will be included in release 7.69.0 label Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.69.0 Issue or pull request that will be included in release 7.69.0 size-L team-mobile-platform Mobile Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

8 participants