davide-scalzo/react-native-mixpanel

Mixpanel instance was not initialized yet. Please run initialize() and wait for its promise to resolve before calling identify(...)

Closed this issue · 1 comments

I catch this error in android 7.0 (Xiaomi redmi note 4x)
device-2018-05-18-165715
Mixpanel instance was not initialized yet. Please run initialize() and wait for its promise to resolve before calling identify(...)

my code:
import {AppRegistry} from 'react-native';
import App from './src/App';
import {bgMessage} from './src/bgMessaging'; // <-- Import the file you created in (2)
import Mixpanel from "react-native-mixpanel"
Mixpanel.sharedInstanceWithToken("token")//prod
Mixpanel.identify("12148");
Mixpanel.track("test")
AppRegistry.registerComponent('Momentum', () => App);
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessage);

"react-native": "0.55.3",
"react-native-mixpanel": "^1.0.2",

My Root component:

constructor(props) {
    super(props);

    console.log(`ROOT IS MOUNTING`);

    this.state = {
      rehydrated: false
    };

    this.initiateMixpanel();
  }

  initiateMixpanel = async () => {
    try {
      const mpInstance = await Mixpanel.sharedInstanceWithToken(
        Config.MIXPANEL_TOKEN
      );

      console.log(`mpInstance:`, mpInstance);

      const doMpStuff = await Promise.all([
        Mixpanel.identify(`${DeviceInfo.uniqueID}`),
        Mixpanel.set({ $deviceName: DeviceInfo.deviceName }),
        Mixpanel.track("App Loaded")
      ]);

      console.log(`doMpStuff:`, doMpStuff);
    } catch (err) {
      console.log(`Error initiating Mixpanel:`, err);
    }
  };