Device Tags

Device Tags script

The Device Tags script is a JavaScript file to be loaded on websites to communicate with the Device Tags service to create or update the user device tag.


Configuration

You can set the following optional configurations in window.icdt:

isDevelopment

Default is false, if set to true then the script uses the Cortex staging API. This can be ignored ignore if you're not using the Cortex staging environment.

consent

Default is undefined, if set to false then no API call will be made. This can be ignored if user consent is not a concern.

token

Expect Cortex JWT token. If the user already logged in before this script is loaded, then you can set the token here. Otherwise, you will need to call the login function later when the user is logged in with the new token (more information on this below).

associatedId

Same as token, but for third party authentication systems (i.e. not Cortex SSO).

anonymous

Default is undefined. Set this to true if you want it to work without token or associatedId and to track anonymous users. This can be ignored if you only want to track logged in users.

server

Default is 'standard', controls top-level domain for most APIs, 'standard' will be used if value isn't 'standard' or 'us'. This can be ignored if you are not USA-based.

timeout

In seconds, default is 3600 (1 hour), controls how much time must pass for another visit to be tracked. It is advised to have a delay to avoid spamming the API.

cookieDomain

Default is undefined, controls the cookie domain.


Usage

You will be given an API key and a client ID.

// Configuration
window.icdt = {
  anonymous: true
  timeout: 0
  cookieDomain: 'mydomain.com'
}

// 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);

SCRIPT_URL is currently https://icdt.incrowdsports.com/icdt.js


Methods

After script load, the following methods are available:

init()

window.icdt.init()

The init function is run when the script is loaded. So in practice, you will not need to call this function manually.

updateDevice()

window.icdt.updateDevice()

The updateDevice function is run when the script is loaded if conditions are met. So in practice, you will not need to call this function manually.

login(token, associatedId)

window.icdt.login(token, associatedId)

The login function will set the new values for token and associatedId in window.icdt if provided, then call updateDevice(). Call this after user login, to update the device with the new token or associatedId. Alternatively you can update the value in window.icdt directly, then call updateDevice() manually:

window.icdt.token = newToken
window.icdt.associatedId = newAssociatedId
window.icdt.updateDevice()

logout()

window.icdt.logout()

The logout function will set token and associatedId to null in window.icdt then call updateDevice(true). Call this after user logout to update the device, and you should use the logout function as calling updateDevice() directly without true will not work after setting token and associatedId to null.


Troubleshooting

Ensure the script is loaded

You can check browser devtools Network tab to see whether the script is loaded.

Ensure the script ran

Enter window.icdt in browser console and check if it returns the configuration object with initiated property set to true.

Ensure the environment is correct

Check if isDevelopment is set correctly.

Difficulty during development and testing

If having trouble to produce a minimal working example for testing purposes, you may want to set anonymous to true to temporarily bypass the requirement of token and associatedId being set.

You may also want to set timeout to 0 to disable the delay of API call between visits.