davide-scalzo / react-native-mixpanel

A React Native wrapper for Mixpanel tracking
MIT License
455 stars 195 forks source link

Sync or async? #57

Open msageryd opened 8 years ago

msageryd commented 8 years ago

I suppose that the calls to Mixpanel are asynchronous. Is it safe to just call the functions and let them take care of themselves? Or are there any initializations that needs to be awaited on?

I'm thinking that sharedInstanceWithToken() might need to be awaited on to ensure everything is initialized before calling track() etc.

Are any of the functions blocking? It would be great to have some more knowledge of this.

Thank you for a great library.

barakcoh commented 7 years ago

I'm starting to think so too, we have a few of these crashes:

Attempt to invoke virtual method 'void com.mixpanel.android.mpmetrics.MixpanelAPI.identify(java.lang.String)' on a null object reference

And https://github.com/mixpanel/mixpanel-android/issues/385 it mentions this exception is thrown when the SDK hasn't been initialized so it seems plausible for a race-condition to occur in React Native apps using Mixpanel.

smkhalsa commented 7 years ago

Any update on this? It seems reasonable to promisify the calls to the underlying mixpanel methods

mxaly commented 7 years ago

+1 run into case when .reset() made .track() to not happen. Ended up with ugly setTimeout ;(

ekeuus commented 7 years ago

Have the same problem, as some calls which are ran on app start fail. Will resort to setTimeout for now, although I'm hoping for a promise-based one.

adamjacob commented 7 years ago

I'm also running into this issue. Starting to see:

Attempt to invoke virtual method 'void com.mixpanel.android.mpmetrics.MixpanelAPI.track(java.lang.String, org.json.JSONObject)' on a null object reference

Any updates on this?

variant77 commented 7 years ago

Same here. Don't know if it's relevant but I see it mostly on older devices running older Android versions.

akshay2604 commented 6 years ago

Any update on this? i am facing the same issue. Attempt to invoke virtual method 'void com.mixpanel.android.mpmetrics.MixpanelAPI.track(java.lang.String, org.json.JSONObject)' on a null object reference

msageryd commented 6 years ago

I find this a bit odd.. No shadow at all over @davodesign84, instead kudus to you.

MixPanel is a commercial product. One would think that they'd support projects like this, as this seems to be the only way to use MixPanel on React Native. Did they miss that RN has grown kind of big? Anyway, I'm not using MixPanel anymore.

davide-scalzo commented 6 years ago

Thanks @msageryd . As you guys might know I don't have time to maintain the library and reached out again to Mixpanel team, let's see if they are interested helping out.

StevePotter commented 6 years ago

Everyone, I am in the middle of creating a PR that will have the initialize return a promise. Your app code will be responsible for not calling the track methods until it has initialized, but that's not a major bummer.

The PR is at https://github.com/davodesign84/react-native-mixpanel/pull/123. You can use it today as it has a backwards compatible API