@snowplow/react-native-tracker
Getting started
$ npm install @snowplow/react-native-tracker --save
Mostly automatic installation
$ react-native link @snowplow/react-native-tracker
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜ Add Files to [your project's name]
- Go to
node_modules
➜ @snowplow/react-native-tracker
and add RNSnowplowTracker.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNSnowplowTracker.a
to your project's Build Phases
➜ Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.snowplowanalytics.react.tracker.RNSnowplowTrackerPackage;
to the imports at the top of the file - Add
new RNSnowplowTrackerPackage()
to the list returned by the getPackages()
method
- Append the following lines to
android/settings.gradle
:
include ':@snowplow_react-native-tracker'
project(':@snowplow_react-native-tracker').projectDir = new File(rootProject.projectDir, '../node_modules/@snowplow/react-native-tracker/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:
compile project(':@snowplow_react-native-tracker')
Usage
import {NativeModules} from 'react-native';
let RNSnowplowTracker = NativeModules.RNSnowplowTracker;
RNSnowplowTracker.initialize('test-endpoint-url', 'post', 'https', 'namespace', 'app-id');
RNSnowplowTracker.trackSelfDescribingEvent({'schema': 'iglu:com.acme/event/jsonschema/1-0-0', 'data': {'message': 'hello world'}}, []);
Available methods
initialize(string endpoint, string method (post or get), string protocol (https or http), string namespace, string appId)
trackSelfDescribingEvent(JSON event, Array<JSON> contexts)