0.2.8 • Published 6 years ago
orda-react-native-amplitude-analytics v0.2.8
react-native-amplitude-analytics
Dependencies
react-native version >0.40
Installation
npm i react-native-amplitude-analytics --save
iOS installation
react-native link react-native-amplitude-analyticsAfter you do that make sure that:
- RNAmplitudeSDK.xcodeproj from 
node_modules/react-native-amplitude-analytics/iosis found within your Xcode Project as a subproject (if it's not add it manually with drag and drop). - libRNAmplitudeSDK.a is found within Linked Frameworks and Libraries under General tab (if it's not add it with the plus button) - (you don't need to add libAmplitude-iOS.a as that will be dealt with by Cocoapods in the next step).
 
- Either
 
- add the following line to your "Podfile": 
pod 'Amplitude-iOS', '~> 4.3.1'and runpod install 
or
- download the Amplitude-iOS sdk from here and add it to your project manually. Make sure the 
Amplitude-iOSdirectory of the SDK is included in the root of your app's ios folder. 
- Run your project (
Cmd+R) 
Android Manual installation
- 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
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')Insert the following lines inside the dependencies block in
android/app/build.gradle:compile 'com.amplitude:android-sdk:2.19.1' // native sdk of amplitude compile project(':react-native-amplitude-analytics') // our react-native moduleAdd permissions. If you haven't already, add the INTERNET permission to your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
Usage
import RNAmplitude from 'react-native-amplitude-analytics';Example
class testApp extends Component {
  constructor() {
    super();
    const amplitude = new RNAmplitude('Your Amplitude key');
	 
    // log an event
    amplitude.logEvent(eventName);
	 
    // log an event with data
    amplitude.logEvent(eventName, { foo: bar });
	 
    // log an event with a custom timestamp (data is optional)
    // timestamp should be the number of milliseconds since Unix epoch
    amplitude.logEventWithTimestamp(eventName, timestamp, { foo: bar });
	 
    // set the user id
    amplitude.setUserId('1D32FS45');
	 
    // set user props
    amplitude.setUserProperties({ hairColor: 'brown' });
    // sets whether or not to opt a user out logging
    amplitude.setOptOut(true);
	 
    // log revenue
    amplitude.logRevenue(productIdentifier, quantity, amount)
	 
    // add to user property
    amplitude.addToUserProperty(property, amount)
    // set user property once
    amplitude.setUserPropertyOnce(property, value)
    // get device id as logged in Amplitude
    amplitude.getDeviceId().then(deviceId => ...)
  }
  ...
}there's also an example project here.
0.2.8
6 years ago