Skip to content

dkpalmer/react-native-amplitude-analytics

 
 

Repository files navigation

react-native-amplitude-analytics

npm version

Dependencies

react-native version >0.40

Installation

npm i react-native-amplitude-analytics --save

iOS installation

Option 1 (link):
  1. react-native link react-native-amplitude-analytics
  2. Either
  • add the following line to your "Podfile": pod 'Amplitude-iOS', '~> 4.0.4' and run pod install

or

  • download the Amplitude-iOS sdk from here and add it to your project manually.
  1. Run your project (Cmd+R)

Option 2 (Cocoapods only)

  1. Add the following line to your "Podfile": pod 'react-native-amplitude-analytics', path: '../node_modules/react-native-amplitude-analytics'
  2. run pod install
  3. Run your project (Cmd+R)

Android Manual installation

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add

    import com.sudoplz.reactnativeamplitudeanalytics.RNAmplitudeSDKPackage;

to the imports at the top of the file.

  • Add

    new RNAmplitudeSDKPackage(MainApplication.this),

to the list returned by the getPackages() method

  1. Append the following lines to android/settings.gradle:

    include ':react-native-amplitude-analytics'
    project(':react-native-amplitude-analytics').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-amplitude-analytics/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

    compile 'com.amplitude:android-sdk:2.13.4' // native sdk of amplitude
    compile project(':react-native-amplitude-analytics') // our react-native module
  3. Add permissions. If you haven't already, add the INTERNET permission to your manifest file:

    <uses-permission android:name="android.permission.INTERNET" />
    

Usage

import RNAmplitute from 'react-native-amplitude-analytics';

Example

class testApp extends Component {
  constructor() {
    super();
	 const amplitude = new RNAmplitute('Your Amplitude key');
	 
	 // log an event
	 amplitude.logEvent(eventName);
	 
	 // log an event with data
	 amplitude.logEvent(eventName, { foo: bar });
	 
	 // set the user id
	 amplitude.setUserId('1D32FS45');
	 
 	 // set user props
	 amplitude.setUserProperties({ hairColor: 'brown' });
	 
	 // log revenue
	 amplitude.logRevenue(productIdentifier, quantity, amount)
  }
  ...
}

there's also an example project here.

About

React Native iOS and Android wrapper for Amplitude

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 30.3%
  • Objective-C 29.5%
  • Java 28.2%
  • Python 8.1%
  • Ruby 3.9%