Official React Native Tracking Library for Mixpanel Analytics
This is the official release for Expo and React Native Web support. For more details, please refer to the release notes for versions 3.0.0-beta.2 and 3.0.0-beta.1.
const MyAsyncStorage = require("@my-org/<library-path>/AsyncStorage"); // or your own storage class
const trackAutomaticEvents = false;
const useNative = false;
const mixpanel = new Mixpanel('YOUR_TOKEN', trackAutomaticEvents, useNative, MyAsyncStorage);
mixpanel.init();
optOutTracking
and optInTracking
consistent with the native SDK.(https://github.com/mixpanel/mixpanel-react-native/pull/225)This version(PR #223) introduces support for Expo, React Native Web, and any platform using React Native that does not support iOS and Android. To activate this, initialize Mixpanel with an additional parameter useNative
set to false, which will enable JavaScript mode. Currently in beta, we plan to iterate on this to address any issues and add more features. We welcome your feedback.
const trackAutomaticEvents = false;
const useNative = false;
const mixpanel = new Mixpanel(
"YOUR_MIXPANEL_TOKEN",
trackAutomaticEvents,
useNative
);
mixpanel.init();
To try the Expo sample app, navigate to Samples/MixpanelExpo
, run npm install
, and then execute npm run ios
or npm run android
To use it in your existing project, please:
npm install mixpanel-react-native@beta
npm install @react-native-async-storage/async-storage
or
yarn add mixpanel-react-native@beta
yarn add @react-native-async-storage/async-storage
When JavaScript mode is enabled, Mixpanel utilizes AsyncStorage to persist data. If you prefer not to use it, or if AsyncStorage is unavailable in your target environment, you can import or define a different storage class. However, it must follow the same interface as AsyncStorage The following example demonstrates how to use a custom storage solution:
const MyAsyncStorage = require("@my-org/<library-path>/AsyncStorage"); // or your own storage class
const trackAutomaticEvents = false;
const useNative = false;
const mixpanel = new Mixpanel('YOUR_TOKEN', trackAutomaticEvents, useNative, MyAsyncStorage);
mixpanel.init();
Known limitations and differences compared to the native mode (iOS/Android):