segmentio / analytics-react-native

The hassle-free way to add analytics to your React-Native app.
https://segment.com/docs/sources/mobile/react-native/
MIT License
361 stars 185 forks source link

track calls immediately after identify don't have userId #584

Closed Asgaroth closed 2 years ago

Asgaroth commented 2 years ago

Steps to reproduce

Do an identify call immediately followed by a track call

client.identify('123')
client.track('Account created') 

Expected behavior

The track call should have a userId property

Actual behavior

The track call acts as if the user were still anonymous.

Adding a delay after the identify works as expected

client.identify('123')
setTimeout(() => { client.track('Account created')  }, 300)
oscb commented 2 years ago

Hi Alex, thanks for the report. We have a repro and we are working on a fix!

bprymicz commented 2 years ago

Note that I'm also seeing the userId missing from a screen call immediately following the identify as well.

holek10 commented 2 years ago

analytics-react-native version: 2.2.2

Bit different use case but the incorrect behaviour seem to be consistent with what has been described above.

We have scenario where we switch user profile and we trigger Identify call right after the profile has been switched. Observed data indicates that track event capturing the switch action (which is triggered at the same time or milliseconds apart as Identify call) is attributed to previous user ID, while an event triggered say 2 seconds after has proper user ID coming from the switched profile.

In our case the workaround with adding a delay will be ugly and will delay the whole app navigation for a solid 1 second, impacting UX.

alanjcharles commented 2 years ago

Fixed in analytics-react-native 2.5.0 Please let us know if you run into any other issues

OskarAtJoint commented 1 year ago

@alanjcharles we still see this problem in 2.10.0, was it really fixed or has it resurfaced?

OskarAtJoint commented 1 year ago

or is it expected/mandatory to do await identify in order for next track call to have the userid ? which seems strange, identify shouldnt be blocking ?

oscb commented 1 year ago

@OskarAtJoint thanks for the report, this is not expected. While you can await for a particular event, it shouldn't be required for userId to be updated. I just figured out the issue with this. Will be fixed in the next release.

OskarAtJoint commented 1 year ago

ok! any idea of when that next release will come?!

oscb commented 1 year ago

@OskarAtJoint I just triggered a release for it. The v2.11.0 has the fixes