Skip to content

fix: wallet telemetry identify#6258

Merged
DanielSinclair merged 4 commits intodevelopfrom
@daniel/wallethash
Nov 22, 2024
Merged

fix: wallet telemetry identify#6258
DanielSinclair merged 4 commits intodevelopfrom
@daniel/wallethash

Conversation

@DanielSinclair
Copy link
Copy Markdown
Contributor

Fixes APP-1956

What changed (plus any additional context for devs)

  • added walletType param to identify and Sentry user
  • setting up Sentry and Rudderstack identify in useInitializeWallet to absorb wallet switches
  • added getWalletContext util to prepare hashes and wallet types consistently throughout the codebase
  • added walletContext overrides in track and screen to support scenarios where the actioned wallet is different than the global selected wallet

Screen recordings / screenshots

What to test

  • confirmed proper hash switching on Rudderstack's side ✅
  • walletType appears to be undefined directly after import because of the following snippet; alternative approach may be necessary
const { wallets } = store.getState();
const wallet = findWalletWithAccount(wallets.wallets || {}, address);

@rainbow-me rainbow-me deleted a comment from linear Bot Nov 8, 2024
@DanielSinclair DanielSinclair added the release for release blockers and release candidate branches label Nov 15, 2024
Copy link
Copy Markdown
Contributor

@brunobar79 brunobar79 left a comment

Choose a reason for hiding this comment

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

Looks great but there's a lint error. Will approve after that!

@DanielSinclair
Copy link
Copy Markdown
Contributor Author

@brunobar79 Done ✅

@brunobar79
Copy link
Copy Markdown
Contributor

Launch in simulator or device for 60032a5

Copy link
Copy Markdown
Contributor

@BrodyHughes BrodyHughes left a comment

Choose a reason for hiding this comment

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

Checked:

  • importing and switching wallets
  • connecting to a dapp
  • accepting / rejecting txns

walletAddressHash and walletType both look consistent and the events seems to populate as expected!

@DanielSinclair DanielSinclair merged commit f8808d8 into develop Nov 22, 2024
@DanielSinclair DanielSinclair deleted the @daniel/wallethash branch November 22, 2024 21:07
olerass added a commit that referenced this pull request Mar 2, 2026
The `Analytics` class currently reads the device ID from MMKV in its field initializer (`device.get(['id'])`), but on a user's very first app open that value doesn't exist yet. Because `loadSettingsData()` calls `analytics.identify()` with `language`, `currency`, and `enabledTestnets` traits during the parallel app startup tasks, those calls hit the early-return guard in `identify()` and the traits are silently dropped. On subsequent app opens the device ID is already persisted in MMKV, so the issue is limited to the first session.

In practice this means new users who open the app once and don't return have permanently empty trait profiles, and first-session analytics for all new users can't be segmented by these properties. The early identify calls generate ~200K Sentry warning events which is what prompted finding this issue to begin with ([example](https://rainbow-me.sentry.io/issues/6865136718/?project=1855565)).

This was introduced in two stages: #6583 (May 2025) rewrote the Analytics class with the `device.get(['id'])` field initializer and `!deviceId` guard, which was safe at the time since `identify()` was only called after `setDeviceId()`. Then #6835 (Sep 2025) moved `loadSettingsData()` into the `Promise.all` block before `getOrCreateDeviceId()`, creating the code path where identify fires before the device ID exists. Sentry confirms the issue started Sep 8, 2025.

The underlying issue is that the `Analytics` class starts the Rudderstack client in its constructor (a side effect of module import), but the device ID has to be set separately later because it isn't available at import time. This forces a split between "client starts" and "device ID is ready."

This change replaces the constructor side effect with an explicit `init()` method that accepts the device ID and starts the client together. The startup sequence now retrieves the device ID and calls `analytics.init()` before the parallel init tasks, so all `identify()` calls during settings loading succeed on every app open, including the first. The redundant workarounds that were patching around this (a bare `identify()` with empty metadata, and a defensive `setDeviceId` in wallet init added in #6258) are cleaned up. As a side benefit, `Sentry.setUser` also runs earlier now, so crashes during migrations or remote config fetch get attributed to a user.

The analytics unit tests have also been unskipped and fixed. They were disabled since Jun 2024 (#5874) because the constructor side effect made the Rudderstack mock very hard to wire up correctly. With init now explicit, the tests can control the lifecycle properly.

Fixes FEPLAT-38.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release for release blockers and release candidate branches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants