Javascript Tracker Core
The Snowplow JavaScript Tracker Core is an node module, available on npm, providing functionality common to both the server-side Snowplow Node.js Tracker and the client-side Snowplow JavaScript Tracker. It supports all the Snowplow event types. Custom contexts and timestamps can be added to all events.
It is automatically included when using the Node.js or JavaScript trackers.
It has two main types of method: setter methods and tracking methods. Setter methods like setUserId store a name-value pair to be added to all future events, while tracking methods like trackPageView track a specific event.
1. Setup
Compatibility
Current release: 4.6.8
The current release of Snowplow Tracker Core is compatible with Node.js versions 10, 12 and 14. Installing it requires npm or yarn.
Installation
Setting up the tracker should be straightforward if you are familiar with npm:
npm install snowplow-tracker-core
or
yarn add snowplow-tracker-core
2. Initialization
Requiring the module
Require the Snowplow Tracker Core module into your code like so:
var trackerCore = require('snowplow-tracker-core');
or if using ES Modules, import like so:
import { trackerCore } from 'snowplow-tracker-core';
Creating a tracker core instance
The tracker core constructor takes two parameters:
- A boolean value indicating whether unstructured events and custom contexts should be base 64 encoded (which defaults to
true) - An optional callback to be executed on every payload before it is returned
const t = trackerCore(false, console.log);
The above example would create a tracker core instance which doesn't use base 64 encoding and which logs all payloads it creates to the console.