react-native-mixpanel icon indicating copy to clipboard operation
react-native-mixpanel copied to clipboard

Sync or async?

Open msageryd opened this issue 8 years ago • 10 comments

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.

msageryd avatar Oct 11 '16 08:10 msageryd

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.

barakcoh avatar Feb 26 '17 09:02 barakcoh

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

smkhalsa avatar Apr 10 '17 07:04 smkhalsa

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

mxaly avatar Jun 09 '17 10:06 mxaly

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.

ekeuus avatar Jun 26 '17 10:06 ekeuus

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?

adamjacob avatar Sep 11 '17 16:09 adamjacob

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

variant77 avatar Oct 18 '17 11:10 variant77

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

akshay2604 avatar Jan 16 '18 10:01 akshay2604

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.

msageryd avatar Jan 16 '18 10:01 msageryd

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.

davide-scalzo avatar Jan 16 '18 23:01 davide-scalzo

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

StevePotter avatar Jan 19 '18 05:01 StevePotter