Logo

Application collectors

Javascript Collector

v2.4.0

The Javascript Collector by Datazoom is an easy to install SDK for your Javascript Collector applications that makes the following data points automatically collectable in real time. The collector can also be configured to make the data points from the media player extensions listed below automatically collectable.

Integration Instructions

Before you begin, you will need to obtain a collector configuration ID from the Datazoom console. This section walks through the essential steps to get the SDK collecting data from your [application platform] application.

Import Datazoom Library

Use the Datazoom Beacon Service

<script src="https://platform.datazoom.io/beacon/v1/config?configuration_id=CONFIG_ID"></script>

With NPM:

npm install @datazoom/collector_app

Initialization

Initialize the Datazoom SDK in your application when your application starts. This only needs to be done once.

import datazoom from "@datazoom/collector_app"

datazoom.init({

    configuration_id: "CONFIG_ID"

});

Accessing Contexts

Global Context

The global context is accessed by calling metadata and event methods directly from the Datazoom library. For example:

datazoom.setMetadata(...);

datazoom.generateEvent(...);

etc.

Custom Contexts

Custom contexts can be created via:

your_context = datazoom.createBaseContext();

This local context is accessed by calling metadata and event methods using the resulting context object.

your_context.setMetadata(...);

your_context.generateEvent(...);

etc.

The context can be destroyed via:

your_context.destroy();

Full Example

import datazoom from "@datazoom/collector_hlsjs"

datazoom.init({

    configuration_id: "CONFIG_ID"

});

widget_context = datazoom.createBaseContext();

/* Set data in global context */

datazoom.setMetadata({page_title: "Hello World"});

/* Set data in custom widget context */

widget_context.setMetadata({widget_state: "active"});

/* Trigger 'loaded' event from widget context. Will include both global and widget state */

widget_context.generateEvent("loaded");

Using Contexts

Unless otherwise noted, the following methods apply to global and custom contexts.

Set Custom Metadata

.setMetadata({ key1: 1, key2: "default" });

Note: This overwrites the entire state. An update can be implemented via a combination of the getMetadata and setMetadata.  

Get Custom Metadata

.getMetadata();

Clear Custom Metadata

Setting nothing would do this, e.g. .setMetadata({})

Generating Custom Events

A ‘custom_’ prefix is automatically added to the event name as seen when collected.

Custom Events

.generateEvent("ButtonClick");

Adding One-Time Metadata

To include metadata for that specific event only, without storing it in the context. This includes metadata “buttonName” with value “xyz”. The relevant global and local state is left unchanged.

.generateEvent("ButtonClick", { buttonName: "xyz" });

Overriding Standard Metadata

The following map contains all standard Datazoom keys whose values can be overridden.

datazoom.overridableMetadata

For example it might contain:

{ ADVERTISING_ID: "datazoom_advertising_id",

  ASSET_ID: "datazoom_asset_id",

  TITLE: "datazoom_title" 

}

These standard keys are reserved and can be used with the .setMetadata() methods. When used they set the value of the standard metadata instead of custom metadata. These keys can be combined with custom keys. For example:

var contentMetadata = {};

contentMetadata.bar = "bar"; // a custom metadata

// the following are for overridable metadata

contentMetadata[datazoom.overridableMetadata.TITLE] = "my_video_title";

contentMetadata[datazoom.overridableMetadata.ASSET_ID] = "xyz1234";

context.setMetadata(contentMetadata); // Or datazoom.setMetadata()

Listening for SDK Events

You can register a listener to be notified of events occurring within the Datazoom SDK lifecycle.

This can be achieved by registering a handler for the Datazoom SDK notification APP_SESSION_START

datazoom.on(datazoom.sdkEvent.APP_SESSION_START, function() {

// Do Something

});

Supported Data Points

Events

Discrete occurrences driven by user interactions or system actions

Fluxdata

Metrics measuring changing parameters over time