Simple React Native wrapper for Amplitude (Android) tracking
-
npm install react-native-amplitude --save
-
Install Amplitude Android SDK more info here
-
Update Gradle settings
// file: android/settings.gradle
...
include ':RNAmplitude'
project(':RNAmplitude').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-amplitude/android')
- Update Gradle build
// file: android/app/build.gradle
...
dependencies {
...
compile project(':RNAmplitude');
}
- Register React Package
Edit android/app/src/main/java/{NAME OF APP}/MainApplication.java and add the import:
import com.threedot.reactnativeamplitude.ReactNativeAmplitudePackage;
and the line
new ReactNativeAmplitudePackage(getApplication())
In below location:
...
import com.threedot.reactnativeamplitude.ReactNativeAmplitudePackage;
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
...
new ReactNativeAmplitudePackage(getApplication())
...
);
}
};
...
//Require the module
import Amplitude from 'react-native-amplitude';
//Init Mixpanel SDK with your project token
Amplitude.initialize(YOUR_PROJECT_TOKEN);
//Log an event
Amplitude.logEvent('appStart');