Quick start guide
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:
npm install --save @snowplow/react-native-tracker
Note that in addition to react
and react-native
, the tracker has two peer dependencies that need to be added as dependencies to your app:
@react-native-async-storage/async-storage
for event and session local storage implementation.react-native-get-random-values
as a polyfill for the Crypto Web APIs.
Instrumentation
Next, in your app create a new tracker using the newTracker
method. As a minimal example:
import { newTracker } from '@snowplow/react-native-tracker';
const tracker = newTracker({
namespace: 'appTracker',
endpoint: COLLECTOR_URL,
});
The newTracker
function takes the tracker configuration as the only argument. There are two required properties within the configuration:
- The tracker namespace, which identifies each tracker instance.
- The collector URL endpoint.
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. As an example, you can track a screen view event like this:
tracker.trackScreenViewEvent({
name: 'my-screen-name',
id: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
type: 'carousel',
transitionType: 'basic'
});