mixpanel / mixpanel-react-native

Official React Native Tracking Library for Mixpanel Analytics
https://mixpanel.com
Apache License 2.0
107 stars 48 forks source link

TypeError: Cannot set property 'distinctId' of undefined when call identify method #230

Open klalex opened 6 months ago

klalex commented 6 months ago

After signup I call mixpanel.identify(email). It logs I see LOG [Mixpanel] Identify '...'. But then immediately get this error:

TypeError: Cannot set property 'distinctId' of undefined.

I've checked email has value. So it's not undefined. Even in mixpanel logs email is displayed for identify.

mixpanel.track() works as expected though.

zihejia commented 6 months ago

hi @klalex , do you mind sharing the full log and the code snippet that can reproduce the issue?

klalex commented 6 months ago

@zihejia I used example from docs:

const mixpanelToken = '...'; const mixpanel = new Mixpanel(mixpanelToken, false); mixpanel.setLoggingEnabled(true); mixpanel.init(); mixpanel.identify(email);

Also when I downgraded to version 2.4.1 it works now. So something wrong with version 3.0

zihejia commented 6 months ago

hi @klalex , would you like to try 3.0.2?

enu-kuro commented 5 months ago

I got the same error. It should be "await mixpanel.init();" because the init function is an async function.

gabgagnon commented 1 month ago

@zihejia In your React-Native example, the init() call is inside a Class Constructor. How can we wait on a Class Constructor in javascript? Also, the MixpanelManager class is pretty wild on itself and Class Components are close to being deprecated. Not sure it is the best solution for the example.

Code-Victor commented 1 week ago

I'm still facing this issue