Getting Started

Overview on the TrustCommander OnSite API.

The TrustCommander OnSite API is used to interact with TrustCommander with JavaScript. It currently only offers methods to receive and update consent, but it will be improved with additional methods in the future.

API Stub

It is necessary to install a JavaScript stub before any of the OnSite API methods can be used. The stub is used to buffer all methods in a JavaScript array until TrustCommander JavaScript is loaded and ready to process the methods. This allows to use the OnSite API before TrustCommander JavaScript was loaded.

window.caReady = window.caReady || [];
window.cact = function() { window.caReady.push(arguments); };

window.caReady is a JavaScript array that buffers the interactions with the API. window.cact is a JavaScript function used to interact with the OnSite API.

In case you work in a big team and are unsure the stub was already installed it is ok to install the JavaScript stub multiple times.

Methods

After installing the stub it is then possible to use any of the OnSite API methods via the window.cact function.

The available methods are listed on the documentation under ONSITE API.

Each method follows a strict signature:

cact(command, [options,] [callback])

Argument

Descriptions

Required

command

A string identifier used to select the desired method.

Required

options

A JavaScript object that includes data passed to the method.

Optional

callback

A JavaScript callback function that is used to receive information or events from the OnSite API.

Optional

Below you will find an example method that is used to receive the TrustCommander consent with the OnSite API. This example only provides a callback to receive the consent without providing any options.

cact('consent.get', function (result) {
if (result.consent.status === "all-on") {
// Consent available for all categories.
}
});

The OnSite API methods are called asynchronously. In case e.g. you need information synchronous in the <head> of the document it is recommended to cache and retrieve the result of the API in localStorage.