Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MixPanel causing app to crash on latest react native #179

Closed
matthewmturner opened this issue Mar 19, 2023 · 38 comments · Fixed by #183 or #188
Closed

MixPanel causing app to crash on latest react native #179

matthewmturner opened this issue Mar 19, 2023 · 38 comments · Fixed by #183 or #188

Comments

@matthewmturner
Copy link

matthewmturner commented Mar 19, 2023

Since upgrading to react native .71 and enabling hermes we have been seeing more crashes and I think they are coming from the native implementation of mixpanel based on the reports we are getting from Sentry. Stack trace included below. We are on version 2.1.

Is this something that you can fix on your side?

image

@matthewmturner
Copy link
Author

I've double checked and every instance of this error weve seen was on iOS 16.1+ with React Native .71 (hermes enabled)

@Allanbcruz

This comment was marked as resolved.

@matthewmturner
Copy link
Author

@Allanbcruz which version of react native are you on?

@Allanbcruz

This comment was marked as resolved.

@matthewmturner
Copy link
Author

Yup same for me only had issues after upgrade. I was on .65 before though.

@matthewmturner
Copy link
Author

It's very inconsistent for me though - what about you? The app still works a good amount of the time it just crashes a lot more than it used to (usually after opening the app).

@Allanbcruz
Copy link

making a "My bad", sorry @matthewmturner, the error I reported was actually caused by me calling the mixpanel track before it had initialized

@matthewmturner
Copy link
Author

@Allanbcruz Had you changed anything about your Mixpanel code when upgrading React Native?

@Allanbcruz
Copy link

No @matthewmturner, due to a failure of the team to manage the releases of our application, there was a coincidence that the faulty code (failed implementation trying to call the mixpanel track before Init()) and the React-Native update version were on the same branch.

@matthewmturner
Copy link
Author

@Allanbcruz Ah ok, thanks for information!

@matthewmturner
Copy link
Author

were going to try upgrading to 0.71.4 to see if that helps. if not we will likely have to disable mixpanel

@matthewmturner
Copy link
Author

Were also going to upgrade from mixpanel 2.1 to 2.2, i see that updated the target deployment version so maybe that will help

@matthewmturner
Copy link
Author

Any feedback from the Mixpanel team please? We updated on our side but it seems likely that the bug is persisting as already saw an instance of it on the version with the fix

@jaredmixpanel
Copy link
Collaborator

@matthewmturner I'm not able to reproduce the crash and this is the only report we have of such a crash, so I'm not sure what the cause is. But from the screenshot of the stack trace we can see that the crash occurs in AutomaticProperties.setAutomaticProperties which can be found here: https://github.com/mixpanel/mixpanel-react-native/blob/master/ios/AutomaticProperties.swift#L7-L9

Which is called from here: https://github.com/mixpanel/mixpanel-react-native/blob/master/ios/MixpanelReactNative.swift#L22

Which receives the superProperties object param from your init call: https://github.com/mixpanel/mixpanel-react-native/blob/master/index.js#L65-L67

Are you providing superProperties in your init call? If so, what are they and how exactly are you doing it? Let me know if you get any additional information and I'll take a closer look.

@matthewmturner
Copy link
Author

@jaredmixpanel thanks for the response! we dont use superProperties anywhere. Below is our core mixpanel code. Using that we just call mixpanelInstance.track throughout the app as needed.

and unfortunately i havent been able to reproduce this in development. im only getting the sentry crash reports in production.

import config from 'config';
import { Mixpanel } from 'mixpanel-react-native';

class MixpanelInstance {
  mixpanel: Mixpanel | null;

  isInitialized: boolean;

  constructor() {
    this.mixpanel = null;
    this.isInitialized = false;
  }

  init() {
    try {
      const trackAutomaticEvents = true;
      const mixpanel = new Mixpanel(config.mixpanelToken, trackAutomaticEvents);
      mixpanel.init();
      this.mixpanel = mixpanel;
      this.isInitialized = true;
    } catch (e) {
      console.error(e);
      this.mixpanel = null;
      this.isInitialized = false;
    }
  }

  identify(userId: string) {
    if (!this.isInitialized) return;
    try {
      // We know from the constructor that if isInitialized is true,
      // then mixpanel is not null
      this.mixpanel!.identify(userId);
    } catch (e) {
      console.error(e);
    }
  }

  updateCurrentUser(properties: Object) {
    if (!this.isInitialized) return;
    try {
      // We know from the constructor that if isInitialized is true,
      // then mixpanel is not null
      this.mixpanel!.getPeople().set(properties);
    } catch (e) {
      console.error(e);
    }
  }

  track(name: string, properties: Object) {
    if (!this.isInitialized) return;
    try {
      // We know from the constructor that if isInitialized is true,
      // then mixpanel is not null
      this.mixpanel!.track(name, properties);
    } catch (error) {
      console.error(error);
    }
  }
}

const mixpanelInstance = new MixpanelInstance();

export { mixpanelInstance };

@jaredmixpanel
Copy link
Collaborator

Not sure how this crash is possible then. The stack trace shows AutomaticProperties.swift line 9 being executed: https://github.com/mixpanel/mixpanel-react-native/blob/master/ios/AutomaticProperties.swift#L9

That line is only executed for each key, value pair in that properties dictionary, so if that dictionary is nil... no idea how we could get to that line. As a workaround it may be worth providing an empty object for the superProperties param or even some sort of static object like {"App Name": "VERSD"}... maybe this will result in a more predictable behavior. In the meantime, I'll add a check to only call setAutomaticProperties if properties is not nil.

@jaredmixpanel
Copy link
Collaborator

@matthewmturner Okay, try updating to v2.2.3 and let me know if that fixed it.

@matthewmturner
Copy link
Author

@jaredmixpanel will do, thanks much.

@matthewmturner
Copy link
Author

@jaredmixpanel unfortunately i'm still getting this error even with the update. Same stack trace. is there anything else we could try?

@jaredmixpanel
Copy link
Collaborator

@matthewmturner ok, i've tried something else, let me know if v2.2.4 fixes it

@matthewmturner
Copy link
Author

@jaredmixpanel great thanks - will include in our next release and let you know.

@jaredmixpanel
Copy link
Collaborator

@matthewmturner v2.2.4 had a bug, sorry about that. please try v2.2.5 and let me know.

@matthewmturner
Copy link
Author

@jaredmixpanel updating in our release today, will keep you posted. thanks.

@matthewmturner
Copy link
Author

matthewmturner commented May 25, 2023

@jaredmixpanel FYI were still having this issue, currently on 2.2.5

@matthewmturner
Copy link
Author

@jaredmixpanel the only other thing I can think to mention is that we've only seen this issue since switching to Hermes / upgrade to RN 0.71. Not sure how those would be related though as this seems to be from the native side.

@matthewmturner
Copy link
Author

Fyi this is report from Crashlytics, a little different.

image

@matthewmturner
Copy link
Author

Do you have any ideas for hacks I can do to get around this?

@matthewmturner
Copy link
Author

@jaredmixpanel from the error seems like it could be related to serverUrl? But we aren't touching that so not sure why its causing issue

@matthewmturner
Copy link
Author

@jaredmixpanel do you have any thoughts here?

@zihejia
Copy link
Contributor

zihejia commented Jun 4, 2023

hi @matthewmturner , I'm reopening this issue for now, I will take a look.

@zihejia zihejia reopened this Jun 4, 2023
@matthewmturner
Copy link
Author

@zihejia Thank you!

@matthewmturner
Copy link
Author

@zihejia hi - just checking in on this.

@zihejia
Copy link
Contributor

zihejia commented Jun 17, 2023

hi @matthewmturner , please try the latest version v2.3.0, and let me know how it goes.

@matthewmturner
Copy link
Author

matthewmturner commented Jun 21, 2023

@zihejia we are continuing to have the problem (the error looks a little different though - image attached). I appreciate that your team has tried putting out several releases to fix this but unless you have a quick fix we are going to stop using mixpanel, its significantly downgrading the quality / experience of using our app and it appears we are no closer to resolving the issue after months.

image

@matthewmturner
Copy link
Author

Closing as we no longer use mixpanel

@TowhidKashem
Copy link

TowhidKashem commented Jul 14, 2023

Closing as we no longer use mixpanel

haha I was just about to comment I am switching to amplitude. I just implemented it and kept getting crashes on production (iOS), in development is works fine. I couldn't even get any errors in sentry cause the app crashes as soon as it's opened. I'm not a native dev so wouldn't even know what to make of the native logs even if I could get em. Screw it the way it's being managed in this thread makes mixpanel looks amateur anyway.

and looks like it happens often, I don't think this lib is production ready one bit:

@catliaw
Copy link

catliaw commented Sep 8, 2023

Hi @TowhidKashem (and anyone who is running into this issue), we have recently looked into this issue again but are not able to reproduce the issue. If you are still running into this issue, can you write into support@mixpanel.com citing this Github issue, attach a sample app that gets the errors/crash issue, and the error messages you're getting? You can mention my name in the email, so it will get assigned to me. Thank you very much in advance.

@gilons
Copy link

gilons commented May 25, 2024

We are in 2024, Was still having this issue out of nowhere, mix panel just started to crash while calling tracking.init with values

    environment: __DEV__ ? "development" : "production",
    platform: Platform.OS,
    version: APP_VERSION,

Was able to fix it while installing the latest version of the library switching away from native side operations as follows

const useNative = false;
const trackAutomaticEvents = true;
const tracking = new Mixpanel(
    "XXXXXXXXXX",
    trackAutomaticEvents,
    useNative,
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants