@snowplow/react-native-tracker
Disclaimer
This project is currently in alpha status.
Feedback and contributions are welcome - if you have identified a bug, please log an issue on this repo. For all other feedback, discussion or questions please open a thread on our discourse forum.
Due to pending design decisions, breaking changes in how the methods are called may be introduced before a beta/v1 release.
Getting started
From the root of your react-js project:
$ npm install @snowplow/react-native-tracker --save
Instrumentation
The tracker will be imported as a NativeModule. Initialise it then call the relevant tracking method:
import Tracker from '@snowplow/react-native-tracker';
Tracker.initialize('test-endpoint', 'post', 'https', 'namespace', 'my-app-id', {
setPlatformContext: true,
setBase64Encoded: true,
setApplicationContext:true,
setLifecycleEvents: true,
setScreenContext: true,
setSessionContext: true,
foregroundTimeout: 600,
backgroundTimeout: 300,
checkInterval: 15,
setInstallEvent: true
});
Tracker.trackSelfDescribingEvent({'schema': 'iglu:com.acme/hello_world_event/jsonschema/1-0-0', 'data': {'message': 'hello world'}}, []);
Running on iOS
cd ios && pod install && cd ..
Run the app with: react-native run-ios
from the root of the project.
Running on Android
react-native run-android
from the root of the project.
Available methods
Instantiate the tracker:
initialize('endpoint',
'method',
'protocol',
'namespace',
'my-app-id',
{
autoScreenView: false,
setPlatformContext: false,
setBase64Encoded: false,
setApplicationContext: false,
setLifecycleEvents: false,
setScreenContext: false,
setSessionContext: false,
foregroundTimeout: 600,
backgroundTimeout: 300,
checkInterval: 15,
setInstallEvent: false
});
Set the subject data:
Setting custom subject data is optional, can be called any time, and can be called again to update the subject. Once set, the specified parameters are set for all subsequent events. (For example, a userid may be set after login, and once set all subsequent events will contain the userid).
setSubjectData({
userId: 'my-userId',
screenWidth: 123,
screenHeight: 456,
colorDepth: 20,
timezone: 'Europe/London',
language: 'en',
ipAddress: '123.45.67.89',
useragent: '[some-user-agent-string]',
networkUserId: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
domainUserId: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
viewportWidth: 123,
viewportHeight: 456
});
Track a custom event:
trackSelfDescribingEvent({
'schema': 'iglu:com.acme/event/jsonschema/1-0-0',
'data': {'message': 'hello world'}
},
[]);
Track a structured event:
trackStructuredEvent('my-category',
'my-action',
'my-label',
'my-property',
50.00,
[]);
Track a Screen View:
Note - for the track Screen View method, if previous screen values aren't set, they should be automatically set by the tracker.
trackScreenViewEvent('my-screen-name',
'63ddebea-a948-4e0c-b458-96467d46f230',
'my-screen-type'
'my-previous-screen',
'my-previous-screen-type',
'e4711a72-c721-4dfa-b51a-a2e201dcec09',
'my-transition-type',
[]);
Track a Page View:
trackPageViewEvent('my-page-url.com',
'my page title',
'my-page-referrer.com',
[]);