ReactNativeTracker

ReactNativeTracker extends Core Tracker with a simplified constructor and some preconfigured Plugins.

Usage

In this example we create a new ReactNativeTracker instance and wrap our entire App in ObjectivProvider.

import { ObjectivProvider, ReactNativeTracker } from '@objectiv/tracker-react-native';
const App = ({children}) => {

const tracker = new ReactNativeTracker({
endpoint: 'https://collector.app.dev',
applicationId: 'app-id'
})

return (
<ObjectivProvider tracker={tracker}>
{children}
</ObjectivProvider>
);
}

Configuration

ReactNativeTracker configuration requires at least an applicationId and either an endpoint or a custom transport.

typedefault value
requiredapplicationIdstring
optionalendpointstring
optionaltransportTrackerTransportThe result of makeReactNativeTrackerDefaultTransport
optionalqueueTrackerQueueThe result of makeReactNativeTrackerDefaultQueue
optionalpluginsTrackerPluginThe result of makeReactNativeTrackerDefaultPluginsList
optionaltrackerIdstringSame value as applicationId
optionalactivebooleantrue
optionalanonymousbooleanfalse
optionaltrackApplicationContextbooleantrue
optionaltrackHttpContextbooleantrue
optionaltrackPathContextFromURLbooleantrue
optionaltrackRootLocationContextFromURLbooleantrue
caution

endpoint and transport are mutually exclusive. While both optional, either one must be specified.

When providing only endpoint, the Tracker will automatically create a Transport configuration initialized with it.

Active state

Trackers may be configured using the active option and modified at runtime via the setActive method.

active

Determines whether the tracker will initialize as active or not. Inactive trackers don't track any Events.

setActive

Allows to programmatically change the tracking state at runtime. This will re-initialize Queue, Transport and Plugins.

Anonymous mode

Anonymous tracking may be configured using the anonymous option and modified at runtime via the setAnonymous method.

anonymous

Determines whether the tracker will initialize in anonymous mode or not. In anonymous mode:

  • No cookies are created client side, nor sent by the remote Collector.
  • The remote Collector will anonymize all HttpContext attributes (remote_address, user_agent).
  • A volatile client session is generated by the Tracker. It will last only until the App is closed, or refreshed.

setAnonymous

Allows to programmatically change anonymous mode at runtime. This will re-initialize Queue, Transport and Plugins.

Defaults

Transport

Fetch API.

Queueing

TrackerQueue is configured to eagerly send max 10 events per batch, each batch is processed every 1000ms.

Persistence

TrackerQueue is configured to use an in-memory Queue.

Retry logic

Configured for 10 retries with exponential backoff starting at 1000ms.

Included plugins

Optional Plugins

Under the hood

The Tracker architecture is highly composable.
To get an idea of how much React Native Tracker automates under the hood, compared to the Core Tracker, this statement:

const tracker = new ReactNativeTracker({ 
applicationId: 'app-id',
endpoint: 'https://collector.app.dev',
});

is equivalent to:

const trackerId = trackerConfig.trackerId ?? trackerConfig.applicationId;
const transport = new FetchTransport({ endpoint: 'https://collector.app.dev' });
const queueStorage = new TrackerQueueMemoryStore()
const trackerQueue = new TrackerQueue({ storage: trackerStorage });
const applicationContextPlugin = new ApplicationContextPlugin({ applicationId: 'app-id' });
const plugins = [applicationContextPlugin];
const tracker = new Tracker({ trackerId, transport, queue, plugins });