Skip to content
Permalink
main
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
___TERMS_OF_SERVICE___
By creating or modifying this file you agree to Google Tag Manager's Community
Template Gallery Developer Terms of Service available at
https://developers.google.com/tag-manager/gallery-tos (or such other URL as
Google may provide), as modified from time to time.
___INFO___
{
"displayName": "iubenda Cookie Solution",
"description": "Cookie consent management for the ePrivacy, GDPR and CCPA.",
"categories": [
"TAG_MANAGEMENT",
"PERSONALIZATION"
],
"securityGroups": [],
"id": "cvt_temp_public_id",
"type": "TAG",
"version": 1,
"brand": {
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAABklJREFUeF7tnU9QHEUUxr/pYRU1loGQEk/CKaQ8CJkh4kmosko8iSfxJJySlKXmzw4xJ/Fkwm5MPKRMTuBJPBlPYnkInsSwG/BgRU4mp2CZmKCm3AjTY/USUiy17PRs92w/qnrOr/ttf7953TOvX886sJdRBRyj3q1zWACGbwILwAIwrIBh9zYCLADDChh2byPAAjCsgGH3NgIsAMMKGHZvI8ACMKyAYfc2AiwAwwoYdr/zImBhcjdW7/bBXWtHxNrL+jl8GWHTMjItc+gZvWdY00TudwaA3yabcffOCCI+DDh9CNnjVUfp8gdANAeHTaNlzxQ6R0uJ1DBgTB9AcWIEcMYRsucT6ePym0A0Dm9sKlG7BhvTBSDu+ju3p8HZG0qaMP4N9rQNU40GmgB+mWhHyZlByF5UEn+jsct/RnM0iBfGlrX0p7ETegCuTDbj6duz4OwljeMEGP8Jf7f1Y4DWukAPQDE/jdB5S6v4jyIh+gpedjiVvuvslBaAq58OAtG3dY5FspnzOg4en5E0Tt2MFoBiblHbvL+ddGI98ILu1JWVdEAHQOHMEHjT15K/W82Mrb0J/+RltU70tCYEIDcFzt7RM6yYXhj/An4w0hBfMU4IAcjfA3eekRZFiAj+8C5mQ4ngsWgFfna3tK8UDWkAKFzqAv/nuvQ4m6IjOJC9WGF/LX8Ya87n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44WAJlMqOoUVAbwZCd6jlQe8mvQnL/VDTEAEpnQjRGIGp+Ky+1AGMmVtbuZl+G9P2dI8wq3tAAUzp4Gx8n0haHzzSBaAGQyoTroEDmkTe8pSCYTqgMAoRJFYhEgkQnVAcDhH6M3GNfRlWofxABIZEJVR1x+iqJzVowagPhMqBYAdL6eSA1AadvvQusQfqMPFn0HPzuos8t6+6IDQDYTWu9IN7cjdFibDgDZmlAdAMSHvYmUKNIBsHChG6ulBR36xvZhP9pXRSLZTGisuhIG1ZJ5Es3SMKETAWJ04t8xGnUR+acNWgAaJT4hPxaAYRgWgAVgWAHD7m0EWACGFTDs3kaABWBYAcPubQRYAIYVMOzeRoAFYFgBw+5tBFgAhhUw7P5/kg1mf/kim+wAAAAASUVORK5CYII=",
"displayName": "iubenda",
"id": "brand_dummy"
},
"containerContexts": [
"WEB"
]
}
___TEMPLATE_PARAMETERS___
[
{
"type": "GROUP",
"name": "defaultConsent",
"displayName": "Purpose default consents",
"groupStyle": "ZIPPY_OPEN",
"subParams": [
{
"type": "SELECT",
"name": "purposeBasic",
"displayName": "Basic functionalities",
"macrosInSelect": false,
"selectItems": [
{
"value": "denied",
"displayValue": "Denied"
},
{
"value": "granted",
"displayValue": "Granted"
}
],
"simpleValueType": true,
"defaultValue": "denied"
},
{
"type": "SELECT",
"name": "purposeExperience",
"displayName": "Experience enhancement",
"macrosInSelect": false,
"selectItems": [
{
"value": "denied",
"displayValue": "Denied"
},
{
"value": "granted",
"displayValue": "Granted"
}
],
"simpleValueType": true,
"defaultValue": "denied"
},
{
"type": "SELECT",
"name": "purposeMeasurement",
"displayName": "Measurement",
"macrosInSelect": false,
"selectItems": [
{
"value": "denied",
"displayValue": "Denied"
},
{
"value": "granted",
"displayValue": "Granted"
}
],
"simpleValueType": true,
"defaultValue": "denied"
},
{
"type": "SELECT",
"name": "purposeAdvertising",
"displayName": "Targeting & Advertising",
"macrosInSelect": false,
"selectItems": [
{
"value": "denied",
"displayValue": "Denied"
},
{
"value": "granted",
"displayValue": "Granted"
}
],
"simpleValueType": true,
"defaultValue": "denied"
},
{
"type": "TEXT",
"name": "waitForUpdate",
"displayName": "Wait for update",
"simpleValueType": true,
"defaultValue": 2000,
"valueValidators": [
{
"type": "NON_NEGATIVE_NUMBER"
}
]
}
]
},
{
"type": "CHECKBOX",
"name": "urlPassthrough",
"checkboxText": "URL passthrough",
"simpleValueType": true,
"defaultValue": true
},
{
"type": "CHECKBOX",
"name": "adsDataRedaction",
"checkboxText": "Ads data redaction",
"simpleValueType": true,
"defaultValue": true
},
{
"type": "SELECT",
"name": "embedCS",
"displayName": "How to embed CS",
"macrosInSelect": false,
"selectItems": [
{
"value": "auto",
"displayValue": "Automatically via GTM template"
},
{
"value": "manual",
"displayValue": "Manually"
}
],
"simpleValueType": true,
"subParams": [
{
"type": "LABEL",
"name": "manualLabel",
"displayName": "See guide at <a href=\"https://www.iubenda.com/en/help/1177-cookie-solution-getting-started#banner\">How to add the cookie consent banner</a>",
"enablingConditions": [
{
"paramName": "embedCS",
"paramValue": "manual",
"type": "EQUALS"
}
]
},
{
"type": "TEXT",
"name": "csConfigurationJson",
"displayName": "CS configuration",
"simpleValueType": true,
"enablingConditions": [
{
"paramName": "embedCS",
"paramValue": "auto",
"type": "EQUALS"
}
],
"lineCount": 10,
"help": "the configuration part (_iub.csConfiguration) of the embedding code displayed in the flow page of iubenda.com (without the callbacks)",
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
},
{
"type": "SELECT",
"name": "csChannel",
"displayName": "CS channel",
"macrosInSelect": false,
"selectItems": [
{
"value": "beta",
"displayValue": "Beta"
},
{
"value": "current",
"displayValue": "Current"
},
{
"value": "stable",
"displayValue": "Stable"
}
],
"simpleValueType": true,
"enablingConditions": [
{
"paramName": "embedCS",
"paramValue": "auto",
"type": "EQUALS"
}
]
}
]
}
]
___SANDBOXED_JS_FOR_WEB_TEMPLATE___
const log = require('logToConsole');
const gtagSet = require('gtagSet');
const setDefaultConsentState = require('setDefaultConsentState');
const updateConsentState = require('updateConsentState');
const GtmObject = require('Object');
const JSON = require('JSON');
const makeInteger = require('makeInteger');
const copyFromWindow = require('copyFromWindow');
const setInWindow = require('setInWindow');
const createQueue = require('createQueue');
const injectScript = require('injectScript');
let isFirstUpdate = true;
let defaultConsent = null;
let iubDataLayerPush;
function main() {
log('data =', data);
gtagSet({
'developer_id.dZTJkMz': true,
url_passthrough: data.urlPassthrough,
ads_data_redaction: data.adsDataRedaction
});
setDefaultConsent({
analytics_storage: data.purposeMeasurement,
ad_storage: data.purposeAdvertising,
personalization_storage: data.purposeExperience,
functionality_storage: data.purposeBasic,
security_storage: data.purposeBasic,
wait_for_update: makeInteger(data.waitForUpdate)
});
setupIubDataLayer();
if (data.embedCS === 'auto') {
embedCS();
} else {
data.gtmOnSuccess();
}
}
function processDataLayerCommand(elem) {
if (typeof elem === 'object') {
if (elem[0] === 'updateConsent') {
updateConsent(elem[1]);
}
}
}
function setDefaultConsent(opts) {
setDefaultConsentState(opts);
defaultConsent = opts;
}
function updateConsent(opts) {
const shouldCheckDefault = !isFirstUpdate;
const payload = {};
for (const key of GtmObject.keys(opts)) {
const val = opts[key];
if (val !== 'undefined') {
if (val) {
payload[key] = 'granted';
continue;
}
if (!shouldCheckDefault) {
continue;
}
const hasDefault = defaultConsent && defaultConsent[key];
payload[key] = hasDefault ? defaultConsent[key] : 'denied';
}
}
if (GtmObject.keys(payload).length !== 0) {
updateConsentState(payload);
isFirstUpdate = false;
}
}
function setupIubDataLayer() {
const windowIub = copyFromWindow('_iub');
if (!windowIub) {
setInWindow('_iub', {});
}
const windowIubDataLayer = copyFromWindow('_iub.gtmDataLayer');
iubDataLayerPush = createQueue('_iub.gtmDataLayer');
setInWindow('_iub.gtmDataLayer.pushCommand', function windowIubDataLayerPush() {
fnApply(iubDataLayerPush, arguments);
fnApply(processDataLayerCommand, arguments);
}, true);
if (windowIubDataLayer) {
for (const item of windowIubDataLayer) {
processDataLayerCommand(item);
}
}
}
function embedCS() {
const csConfiguration = JSON.parse(data.csConfigurationJson);
if (typeof csConfiguration !== 'object') {
log('csConfiguration is not valid');
data.gtmOnFailure();
return;
}
csConfiguration.googleConsentMode = 'template';
const windowIub = copyFromWindow('_iub');
if (!windowIub) {
setInWindow('_iub', {});
}
setInWindow('_iub.csConfiguration', csConfiguration);
embedScripts(csConfiguration, () => {
log('embedded CS scripts');
data.gtmOnSuccess();
}, () => {
log('failed to embed CS scripts');
data.gtmOnFailure();
});
}
function embedScripts(config, onSuccess, onFail) {
const channel = data.csChannel;
const scriptsToInject = [];
if (config.enableTcf || config.enableCMP) {
const tcfStub = makeUrl(channel, 'tcf', 'stub.js');
const safeTcf = makeUrl(channel, 'tcf', 'safe-tcf.js');
scriptsToInject.push(tcfStub, safeTcf);
}
if (config.enableCcpa) {
const ccpaStub = makeUrl(channel, 'ccpa', 'stub.js');
scriptsToInject.push(ccpaStub);
}
scriptsToInject.push(makeUrl(channel, '', 'iubenda_cs.js'));
let scriptsInjected = 0;
let failed = false;
const localOnSuccess = () => {
scriptsInjected++;
if (scriptsInjected === scriptsToInject.length && !failed) {
onSuccess();
}
};
const localOnFail = () => {
if (!failed) {
failed = true;
onFail();
}
};
for (const script of scriptsToInject) {
injectScript(script, localOnSuccess, localOnFail);
}
if (scriptsToInject.length === 0) {
onSuccess();
}
}
function makeUrl(channel, feature, script) {
const featurePart = feature ? feature + '/' : '';
const channelPart = channel === 'current' ? '' : channel + '/';
return 'https://cdn.iubenda.com/cs/' + featurePart + channelPart + script;
} // This function acts like Function.prototype.apply, which does not work in the sandbox environment
function fnApply(fn, args) {
switch (args.length) {
case 0:
return fn();
case 1:
return fn(args[0]);
case 2:
return fn(args[0], args[1]);
case 3:
return fn(args[0], args[1], args[2]);
default:
return fn(args[0], args[1], args[2], args[3]);
}
}
main();
___WEB_PERMISSIONS___
[
{
"instance": {
"key": {
"publicId": "logging",
"versionId": "1"
},
"param": [
{
"key": "environments",
"value": {
"type": 1,
"string": "debug"
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "write_data_layer",
"versionId": "1"
},
"param": [
{
"key": "keyPatterns",
"value": {
"type": 2,
"listItem": [
{
"type": 1,
"string": "developer_id.dZTJkMz"
},
{
"type": 1,
"string": "url_passthrough"
},
{
"type": 1,
"string": "ads_data_redaction"
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "access_consent",
"versionId": "1"
},
"param": [
{
"key": "consentTypes",
"value": {
"type": 2,
"listItem": [
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "consentType"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
}
],
"mapValue": [
{
"type": 1,
"string": "ad_storage"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "consentType"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
}
],
"mapValue": [
{
"type": 1,
"string": "analytics_storage"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "consentType"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
}
],
"mapValue": [
{
"type": 1,
"string": "functionality_storage"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "consentType"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
}
],
"mapValue": [
{
"type": 1,
"string": "personalization_storage"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "consentType"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
}
],
"mapValue": [
{
"type": 1,
"string": "security_storage"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "consentType"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
}
],
"mapValue": [
{
"type": 1,
"string": "wait_for_update"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
}
]
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "access_globals",
"versionId": "1"
},
"param": [
{
"key": "keys",
"value": {
"type": 2,
"listItem": [
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "key"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
},
{
"type": 1,
"string": "execute"
}
],
"mapValue": [
{
"type": 1,
"string": "_iub"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": false
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "key"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
},
{
"type": 1,
"string": "execute"
}
],
"mapValue": [
{
"type": 1,
"string": "_iub.csConfiguration"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": false
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "key"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
},
{
"type": 1,
"string": "execute"
}
],
"mapValue": [
{
"type": 1,
"string": "_iub.gtmDataLayer"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": false
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "key"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
},
{
"type": 1,
"string": "execute"
}
],
"mapValue": [
{
"type": 1,
"string": "_iub.gtmDataLayer.pushCommand"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": false
}
]
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "inject_script",
"versionId": "1"
},
"param": [
{
"key": "urls",
"value": {
"type": 2,
"listItem": [
{
"type": 1,
"string": "https://cdn.iubenda.com/cs/*.js"
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
}
]
___TESTS___
scenarios: []
___NOTES___
1.1.0 - 2022-08-10
* Add wait_for_update parameter, https://app.asana.com/0/215506225642940/1202738066967665/f
1.0.0 - 2022-07-01
==================
* Initial release