react-native-amplitude-analytics
Dependencies
react-native
version >0.40
Installation
npm i react-native-amplitude-analytics --save
react-native link react-native-amplitude-analytics
iOS installation
- Open your app
.xcodeproj
file - Add the following line to your "Podfile":
pod 'Amplitude-iOS', '~> 3.14.1'
- run
pod install
- Run your project (
Cmd+R
)
Android Manual installation
- Open up
android/app/src/main/java/[...]/MainApplication.java
to the imports at the top of the file.
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.13.4' // native sdk of amplitude
compile project(':react-native-amplitude-analytics') // our react-native module
-
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');
amplitude.amplitude(eventName);
amplitude.amplitude(eventName, { foo: bar });
amplitude.setUserId('1D32FS45');
amplitude.setUserProperties({ hairColor: 'brown' });
amplitude.logRevenue(productIdentifier, quantity, amount)
}
...
}
there's also an example project here.