Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Method to receive Commanders Act consent and consent metadata OnSite via JavaScript.
The Commanders Act OnSite API stub has to be installed before using any of the OnSite API functions.
cact('consent.get', function (result) { ... });
The consent.get
method takes one callback JavaScript function as an argument that gets called with the Consent Object that is currently stored on the browser. The callback is called once after Commanders Act CMP JavaScript loaded and validated the stored consent.
The OnSite API works asynchronous. In case you need the consent synchronous (e.g. in the <head>
of a document for AB Testing or personalisation solutions) it is recommended to cache the object in the localStorage
of the browser. In this case it is crucial to implement the consent.onUpdate
method to keep the cached consent in sync.
In this example the Analytics category was configured with the consent category id 2 in Commanders Act banner.
In this example the Analytics category was configured with the consent category id 2 and the vendor Google with vendor id 5 in Commanders Act CMP.
Overview on the Commanders Act Consent OnSite API.
The Commanders Act Consent API is used to interact with Commanders Act Consent with JavaScript. It currently only offers methods to receive and update consent, but it will be improved with additional methods in the future.
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 Commanders Act consent banner JavaScript is loaded and ready to process the methods. This allows to use the OnSite API before Commanders Act Consent Banner (JavaScript file) was loaded.
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.
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 in the documentation under ONSITE API.
Each method follows a strict signature:
Below you will find an example method that is used to receive the Commanders Act consent status with the OnSite API. This example only provides a callback to receive the consent without providing any options.
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
.
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
Method to update Commanders Act consent status OnSite via JavaScript.
The Commanders Act OnSite API stub has to be installed before using any of the OnSite API functions.
The consent.update
method allows to update the consent with JavaScript. It has to be called with a Consent Object that includes the updated settings. Commanders Act will deep merge the status fields of the current Consent Object with the provided object and automatically update all meta properties and the consent.status
property automatically. In case a consent.status
field is provided with value all-on, all-off or unset all other updates are ignored and all categories and vendor settings will be set to on, off or unset accordingly.
All not configured categories and vendors are ignored when deep-merging the consent objects.
Below you can see how the Consent Object is affected by this update.
Specifying a category or vendor will not have any effect.
Below you can see how the Consent Object is affected by this update.
Specifying a category or vendor will not have any effect.
Below you can see how the Consent Object is affected by this update. Note: required categories are not affected.
You can specify an action inside the update parameters:
This action value will be used to compute your dashboard metrics.
If it is omitted, the default value is banner_button
.
The allowed values are:
banner_button
pc_save
page_click
scroll
browse
Additionally, the following values are allowed for optout only (status: 'all-off'
):
banner_cross
Method to obtain Commanders Act consent when it becomes available.
Method to obtain consent when it becomes available.The Commanders Act OnSite API stub has to be installed before using any of the OnSite API functions.
The consent.onReady
method allow to subscribe a callback function for when consent is set. The callback function will be called only once, with the updated Consent Object. It is called whenever the consent is set via a consent banner interaction or when a consent cookie is already set.
Like in the command consent.onUpdate
, the consentObject
argument will be enriched with the property updateEvent
, but only with the value 'set
'.
In this example, the code is waiting for the user's interaction with the consent banner. The Analytics category was configured with the consent category id 2 on privacy banner.
JavaScript method to display your consent banner.
The command consentBanner.show
allows to redisplay the consent banner for specific reasons. Simply use the following Javascript method:
cact('consentBanner.show')
This command allows you to display the consent banner after the user consent is given
Method to subscribe to Commanders Act consent status updates OnSite via JavaScript.
Method to subscribe to Commanders Act consent updates OnSite via JavaScript.The Commanders Act OnSite API stub has to be installed before using any of the OnSite API functions.
The consent.onUpdate
method allow to subscribe a callback function for consent updates. The callback function will be called with the updated Consent Object. It is called whenever the consent is changed via a Commanders Act banner interaction or the consent.update
method of the OnSite API.
The consentObject
argument will also be enriched with an additional property updateEvent
to signal how the update happened. It can have following values:
When consent is revoked it fires two events: One changed followed by one revoked.
In this example the Analytics category was configured with the consent category id 2 in Commanders Act Consent settings.
In this example the Analytics category was configured with the consent category id 2 in TrustCommander.
Method to revoke Commanders Act consent OnSite via JavaScript.
consent.revoke
is called with no options and no callback function. It resets the consent, consent id and initiates two consen.onUpdate
events, one with the updateEvent
set to changed
, and a second one set torevoked
that allows to perform cleanup tasks like removing cookie identifiers.
The Commanders Act has to be installed before using any of the OnSite API functions.
Value
Description
set
The consent was set.
changed
Consent was already established and then changed.
revoked
Consent was revoked by the user. Used for cleanup tasks like deleting cookie identifiers.
JavaScript method to hide your consent banner.
The command consentBanner.hide
allows to hide the consent banner for specific reasons. Simply use the following Javascript method:
cact('consentBanner.hide')
JavaScript method to display your consent center (consent categories menu).
The command consentCenter.show
allows to redisplay the consent center for specific reasons. Simply use the following Javascript method:
cact('consentCenter.show')
This command allows you to display the consent center after the user consent is given
JavaScript method to hide your consent center (consent categories menu).
The command consentCenter.hide
allows to hide the consent center for specific reasons. Simply use the following Javascript method:
cact('consentCenter.hide')