In order to start sending events using the Snowplow React Native Tracker, the following steps are involved:
Installation
To install the tracker, add it as a dependency to your React Native app:
Code language: Bash (bash)npm install --save @snowplow/react-native-tracker
Instrumentation
Next, in your app create a new tracker using the createTracker
method. As a minimal example:
import { createTracker } from '@snowplow/react-native-tracker';
const tracker = createTracker(
'appTracker',
{
endpoint: COLLECTOR_URL,
},
);
Code language: JavaScript (javascript)
The createTracker
function takes as arguments:
- Required: The tracker namespace, which identifies each tracker
- Required: The Network configuration
- Optional: The Tracker Controller configuration
The optional Tracker Controller configuration has as type definition:
interface TrackerControllerConfiguration {
trackerConfig?: TrackerConfiguration,
sessionConfig?: SessionConfiguration,
emitterConfig?: EmitterConfiguration,
subjectConfig?: SubjectConfiguration,
gdprConfig?: GdprConfiguration,
gcConfig?: GCConfiguration
}
Code language: TypeScript (typescript)
In other words, it provides a way for a fine grained tracker configuration.
As an example to create a tracker with all configurations provided (wherever applicable, the default values are shown):
const tracker = createTracker(
'appTracker',
{
endpoint: COLLECTOR_URL,
method: 'post'
},
{
trackerConfig: {
appId: 'my-app-id',
devicePlatform: 'mob',
base64Encoding: true,
logLevel: 'off',
applicationContext: true,
platformContext: true,
geoLocationContext: false,
sessionContext: true,
deepLinkContext: true,
screenContext: true,
screenViewAutotracking: true,
lifecycleAutotracking: false,
installAutotracking: true,
exceptionAutotracking: true,
diagnosticAutotracking: false
},
sessionConfig: {
foregroundTimeout: 1800,
backgroundTimeout: 1800
},
emitterConfig: {
bufferOption: 'single',
emitRange: 150,
threadPoolSize: 15,
byteLimitPost: 40000,
byteLimitGet: 40000
},
subjectConfig: {
userId: 'my-user-id',
networkUserId: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
domainUserId: '7cdd5ea8-b0f5-47ea-a8bb-5ec8e98cdbd6',
useragent: 'some-useragent-string',
ipAddress: '123.45.67.89',
timezone: 'Europe/London',
language: 'en',
screenResolution: [123, 456],
screenViewport: [123, 456],
colorDepth: 20
},
gdprConfig: {
basisForProcessing: 'consent',
documentId: 'my-gdpr-doc-id',
documentVersion: '1.0.0',
documentDescription: 'my gdpr document description'
},
gcConfig: [
{
tag: 'my-first-gc-tag',
globalContexts: [
{
schema: 'my-gc-schema-01',
data: {gcData: 'some data'}
},
{
schema: 'my-gc-schema-02'
data: {moreGCData: 'some more data'}
},
]
},
{
tag: 'another-gc-tag',
globalContexts: [
{
schema: 'my-gc-schema-03'
data: {gcProp: 'some value'}
},
]
}
]
}
);
Code language: JavaScript (javascript)
Track events
Once the tracker is initialized, you can use the tracker methods to track events, about which you can find out more in the following Tracking events section.