Developer Functions
This part of the instructions is addressed to the developers who deal with the integration with the Elmo banner.
Display of consensus
The window.Elmo object, available when the Elmo banner is initialised, is enriched with the window.Elmo.consents property.
This property is an array where the consents categories are set as the key and the values are booleans indicating the consents.
Consent Callback
Elmo exposes a callback function (window.ElmoOnAccept) which is executed when the user gives consent.
An example of JavaScript code that exploits the two new properties could be as follows:
//Implement the callback function
window.ElmoOnAccept = function () {
//The user has given consent and the consents are updated
console.log(window.Elmo.consents); //Print the updated consents in the console
if (window.Elmo.consents.marketing) {
//If I have the marketing consent I do something, like launch a script or display a modal...in which case I print to the console
console.log("I have marketing consent");
}
}
Update Consents
Elmo exposes a consent update function (Elmo.accept) that is executed to update the user's consents (as if it were the 'Accept all', 'Accept required' or 'Accept selected' button)
The Elmo.accept function accepts as a parameter an array containing the purposes of the cookies to be accepted.
An always-updated list of purposes is exposed via the Elmo.purposes object, which contains the strings to be included in the array to be passed to the function
An example of Javascript code that exploits the new properties might look like the following:
//Reset acceptance to default values (only necessary)
Elmo.accept();
//Impose acceptance only for marketing and necessary
Elmo.accept([
Elmo.purposes.necessary,
Elmo.purposes.marketing
]);
Add Consents
Elmo exposes a function to add a specific type of consent (Elmo.addConsent). A use case could be if the user refuses marketing consent, but this is used to submit data from a form.
In this case one could bind the Elmo.addConsent function to the consent checkbox of the form, so that the Elmo consents are updated in real time if the user accepts the consent to submit the form.
The Elmo.addConsent function accepts as a parameter an array containing the cookie purposes to be added to the existing consent.
An always-updated list of purposes is exposed via the Elmo.purposes object, which contains the strings to be inserted into the array to be passed to the function.
If the user has already given consent to a purpose which is passed to Elmo.addConsent , nothing happens, otherwise it is added to the consents given by the user.
An example of Javascript code that takes advantage of the new properties could be the following:
//Add consent for marketing to those already given by the user.
Elmo.addConsent([
Elmo.purposes.marketing
]);
Remove Consents
Elmo exposes a function to remove a specific type of consent (Elmo.removeConsent). A use case may be if the user refuses marketing consent, but this is used to submit data from a form.
In this case one could bind the Elmo.removeConsent function to the consent checkbox of the form, so that the Elmo consents are updated in real time if the user rejects the consent to submit the form.
The Elmo.removeConsent function accepts as a parameter an array containing the cookie purposes to be removed from the existing consent.
An always-updated list of purposes is exposed via the Elmo.purposes object, which contains the strings to be included in the array to be passed to the function.
If the user has already given consent to a purpose that is passed to Elmo.removeConsent this is removed, otherwise nothing happens.
Elmo.purposes.necessary is necessary and CANNOT be removed.
An example of JavaScript code that takes advantage of the new properties could be as follows:
//Remove consent for marketing from those already expressed by the user.
Elmo.removeConsent([
Elmo.purposes.marketing
]);