Device Tags

Overview

The Device Tags script is a JavaScript file designed to be loaded on websites to create and maintain device-related information. This information includes deviceId, lastSession, and sessionCount, which are stored using cookies. The collected data is then used to communicate with the Device Tags service to create or update the user device tag accordingly.

Features

  • Device ID: A v4 UUID that uniquely represents a device. This ID is stored in client-side web storage (not session storage).
  • Last Session: Tracks the last session time of the user.
  • Session Count: Keeps a count of the number of sessions for the user.

Storage

  • Device ID: Stored in client-side web storage to ensure it persists across sessions.
  • Cookies: Used to store lastSession and sessionCount.

Usage

Optional Configuration

You can configure the Device Tags script by setting the window.icdt object with the following optional parameters:

window.icdt = {
    isDevelopment: true, // default is false, if true then uses staging API
    consent: false, // default is undefined (which acts as true in implementation)
    token: 'InCrowd_JWT_Token', // default is undefined
    associatedId: 'third_party_id_or_token', // default is undefined
    anonymous: true, // allow anonymous user, default is undefined (which acts as false in implementation), if falsy, then need `token` or `associatedId` to work
    server: 'us', // default is 'standard', controls Top-level domain for most APIs, 'standard' will be used if value isn't 'standard' or 'us'
    timeout: 0, // in seconds, default is 3600 (1 hour), controls how long needs to be passed for another visit to be tracked
    cookieDomain: 'mydomain.com', // default is undefined, controls the cookie domain
};

Script Initialization

Replace SCRIPT_URL, API_KEY, and CLIENT_ID with your actual values and include the following script to initialize the Device Tags functionality:

// Remember to replace SCRIPT_URL, API_KEY, and CLIENT_ID
(function(w,d,s,n,u,k,c){
    w[n]=w[n]||{};
    w[n].apiKey=k;
    w[n].clientId=c;
    var f=d.getElementsByTagName(s)[0];
    var j=d.createElement(s);
    j.async=1;
    j.src=u;
    f.parentNode.insertBefore(j,f);
})(window,document,'script','icdt',SCRIPT_URL,API_KEY,CLIENT_ID);

Available Functions

After the script is loaded, the following functions are available:

  • window.icdt.init(): Rerun the init function.
  • window.icdt.updateDevice(): Rerun the updateDevice function.
  • window.icdt.login(token, associatedId): Call this after login to update the device with a new token or associatedId.
  • window.icdt.logout(): Call this after logout to set token and associatedId to null and then update the device.

Example

// Example of how to configure and initialize the Device Tags script
window.icdt = {
    isDevelopment: true,
    consent: true,
    token: 'InCrowd_JWT_Token',
    associatedId: 'third_party_id_or_token',
    anonymous: false,
    server: 'us',
    timeout: 3600,
    cookieDomain: 'mydomain.com',
};

(function(w,d,s,n,u,k,c){
    w[n]=w[n]||{};
    w[n].apiKey=k;
    w[n].clientId=c;
    var f=d.getElementsByTagName(s)[0];
    var j=d.createElement(s);
    j.async=1;
    j.src=u;
    f.parentNode.insertBefore(j,f);
})(window,document,'script','icdt','https://icdt.incrowdsports.com/icdt.js','API_KEY','CLIENT_ID');