Skip to content

Tredsite/react-native-mixpanel

 
 

Repository files navigation

React-Native-Mixpanel

Super simple React Native wrapper for Mixpanel tracking

Installation

  1. npm install react-native-mixpanel --save
  2. Install Mixpanel iOS SDK via either Cocoapods or manually more info here
  3. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  4. Go to node_modulesreact-native-mixpanel and add RNMixpanel.xcodeproj
  5. In XCode, in the project navigator, select your project. Add libRNMixpanel.a to your project's Build PhasesLink Binary With Libraries
  6. Click RNMixpanel.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive.
  7. Run your project (Cmd+R)

##Usage##

// Require the module
var Mixpanel = require('react-native-mixpanel');

// Init Mixpanel SDK with your project token
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN);

// Send and event name with no properties
Mixpanel.track("Event name");

// Track event with properties
Mixpanel.trackWithProperties('Click Button', {button_type: 'yellow button', button_text: 'magic button'});

// Create Alias from unique id
Mixpanel.createAlias(UNIQUE_ID);

// Identify 
Mixpanel.identify(UNIQUE_ID);

// Get Distinct ID
Mixpanel.getDistinctId(function(id){
	console.log(id);
})

// Set People properties
Mixpanel.set({"$email": "elvis@email.com"});

// Timing Events
// Sets the start time for an action, for example uploading an image
Mixpanel.timeEvent("Image Upload");
// to be followed by a tracking event to define the end time
Mixpanel.track("Image Upload");

// Register super properties
Mixpanel.registerSuperProperties({"Account type": "Free", "User Type": "Vendor"});

// Register super properties Once
Mixpanel.registerSuperProperties({"Gender": "Female"});

// Track Revenue
Mixpanel.trackCharge(399);

// Track with properties
Mixpanel.trackCharge(399, {"product": "ACME Wearable tech"});

// Increment property
Mixpanel.increment("Login Count", 1);

// Mixpanel reset method
Mixpanel.reset();

Testing Locally

Run npm pack: This will generate a tarball release of your npm module named after your project. You can then use this in your other repositories to test.

Notes

For more info please have a look at the official Mixpanel reference for iOS.

About

A React Native wrapper for Mixpanel tracking

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 75.7%
  • Java 22.7%
  • Ruby 1.3%
  • JavaScript 0.3%