davide-scalzo / react-native-mixpanel

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

Mixpanel.sharedInstanceWithToken is not a function #244

Open ghasemikasra39 opened 4 years ago

ghasemikasra39 commented 4 years ago
const Mixpanel = require('react-native-mixpanel');
Mixpanel.sharedInstanceWithToken(MIXPANEL_TOKEN_DEVELOPMENT, false, false);
Screenshot 2020-06-19 at 14 11 23
System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 22.38 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
    Yarn: 1.22.4 - ~/Documents/youpendo-app-bareworkflow/node_modules/.bin/yarn
    npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6392135
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_232 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: ^4.8.0 => 4.10.0
    react: 16.11.0 => 16.11.0
    react-native: 0.62.2 => 0.62.2
  npmGlobalPackages:
    *react-native*: Not Found
   "react-native-mixpanel": "^1.2.0",
bpfeiffer187 commented 4 years ago

so this is how i have it working. Granted i created a wrapper function.

import Mixpanel from 'react-native-mixpanel';

const logToMixpanel = (eventName: string, eventData = {}) => { if (isMixpanelEnabled()) { Mixpanel.sharedInstanceWithToken(mixpanelToken()).then(() => { Mixpanel.trackWithProperties(eventName, {...DataLayer, ...eventData}); }); } };

ghasemikasra39 commented 4 years ago

Dear @bpfeiffer187 Tested, getting the same error

tibbus commented 4 years ago

I cannot believe that I have wasted hours with this. The solution is: import mixpanel from 'react-native-mixpanel'; instead of using require