Skip to content

euwyn/react-native-amplitude

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-amplitude

Simple React Native wrapper for Amplitude (Android) tracking

Installation

  1. npm install react-native-amplitude --save

  2. Install Amplitude Android SDK more info here

  3. Update Gradle settings

// file: android/settings.gradle
...
include ':RNAmplitude'
project(':RNAmplitude').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-amplitude/android')
  1. Update Gradle build
// file: android/app/build.gradle
...

dependencies {
    ...
    compile project(':RNAmplitude');
}
  1. Register React Package
...
import com.threedot.reactnativeamplitude.ReactNativeAmplitudePackage; // import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

    private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);

        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())

                // register package here
                .addPackage(new ReactNativeAmplitudePackage(this,getApplication()))

                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);
        setContentView(mReactRootView);
    }
...

Usage

//Require the module
var Amplitude = require('react-native-amplitude');

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

//Log an event
Amplitude.logEvent('appStart');

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published