Events from nodeJS

Step 1: Add dependencies in package.json

In your package.json, include the following in dependencies

"dependencies": {
"datacoral-slice-event-tracker-nodejs": ""

Step 2: Sample nodeJS Instrumentation

You will receive the following information about your events slice:

  1. Event Slice Endpoint
  2. API Keys for different environments

Substituting the appropriate environment parameters in the examples below.

URL_ENDPOINT : The URL of your Datacoral Events API gateway. Ex.

API_KEY : The Datacoral API key to authorize the events invocations. Ex. 1js9q5Gqmk2VDv2omx2WI3yUGV0K7b464fWUJXDX

ENVIRONMENT : Set the environment as dev or prod, based on the emitter of the events

NAMESPACE : The name of this Tracker instance to include with events sent to the collector. The namespace argument attached to every event fired by the new tracker. This allows you to later identify which tracker fired which event if you have multiple trackers running. Ex. landing_pages

APP_ID : Name of application to include with events sent to the collector. The application ID is used to distinguish different applications that are being tracked by the same Snowplow stack. Ex. "finance" or "hr"

// Initialize the tracker
var datacoral = require('datacoral-slice-event-tracker-nodejs');
var emitter = datacoral.emitter;
var tracker = datacoral.tracker;
// Initialize an emitter instance. This object will be responsible for how and when events are sent to datacoral.
var e = emitter(
'URL_ENDPOINT', // Collector endpoint
'AP_KEY', // api key
'ENVIRONMENT', // datacoral environment
1, // Only send events once n are buffered. Defaults to 1 for GET requests and 10 for POST requests.
function (error, response, body) { // Callback called for each request
if (error) {
console.log("Request to apigateway Collector failed!", response);
// Substitute appropriate value for appID.
var t = tracker([e], 'NAMESPACE', 'APP_ID', true);
// You can set the user ID to any string:
var datajson = {
data: {
price: 20
var experiment_context = {
name: "experiment",
data: {
key1: 'value1',
key2: 'value2',
var custom_context = {
name: "custom",
data: {
pageType: 'test',
lastUpdated: new Date(2014,1,26)
var contexts = [experiment_context, custom_context];
t.trackUnstructEvent(datajson, contexts);