If you’re switching from another cookie management solution to ours, you may want to migrate the consents you’ve already collected. This is useful for ensuring that users who have already given their consent under the previous solution are not presented with the cookie banner, and the related request for consent, again.
There are two ways to do this, depending on whether the “old” platform provides a cookie (synchronous method) or requires a call to its API (asynchronous method).
Synchronous method
Before embedding the Privacy Controls and Cookie Solution you’ll need to define a synchronous function (e.g. isConsentGivenByOtherPlatform) to get the consent from the other platform:
<script type="text/javascript">
function readLocalCookie(cookieName) {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var e=cookies[i].split('=');
if (e[0] === cookieName) {
return e[1];
}
}
return null;
}
function isConsentGivenByOtherPlatform() {
var otherPlatformCookieName = 'cookie_from_other_platform'; // use the actual cookie name saved by the other platform
var prevConsent = readLocalCookie(otherPlatformCookieName);
if (prevConsent) {
return true;
} else {
return false;
}
}
</script>
Important
Don’t copy and paste the code shown above — it’s just sample code we’ve provided to help you understand the approach.
Next, add the Privacy Controls and Cookie Solution snippet, invoking the onReady callback:
<script type="text/javascript">
var _iub = _iub || [];
_iub.csConfiguration = {
"lang": "en",
"siteId": XXXXXX, // use your siteId
"cookiePolicyId": YYYYYY, // use your cookiePolicyId
"banner": {
"acceptButtonDisplay": true,
"customizeButtonDisplay": true,
"position": "float-top-center"
},
"callback": {
"onReady": function() {
if (typeof window.isConsentGivenByOtherPlatform === 'function' && isConsentGivenByOtherPlatform()) {
_iub.cs.api.setPreferences({
consent: true,
ccpa: true,
uspr: {
'all': true,
'sd8': true,
'sd9': true,
},
purposes: {
'1': true,
'2': true,
'3': true,
'4': true,
'5': true,
},
tcfv2: {
'all': true,
},
gac: {
'all': true,
},
}, true);
}
}
}
};
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>
The onReady callback checks if consent is already given on another platform and, if so, stores it calling the _iub.cs.api.setPreferences() method.
Per-category consent
_iub.cs.api.storeConsent() allows to customize purposes too in the argument which can be {consent: true}, {consent: false} or {purposes: {1: true, 2: false, …}}.
Asynchronous method
Before embedding the Privacy Controls and Cookie Solution code you’ll need to define a function that:
- accepts a callback;
- detects the consent;
- saves the consent in a global variable; and
- invokes the callback afterward.
Here’s a sample:
<script type="text/javascript">
// fetch consent asynchronously from 3rd party
function getConsentByOtherPlatform(cb) {
$.getJSON('http://otherplatform.com/api/get-consent', function(result) {
if (result.given) {
window.consentByOtherPlatform = true;
} else {
window.consentByOtherPlatform = false;
}
cb();
});
}
function isConsentGivenByOtherPlatform() {
return !!window.consentByOtherPlatform;
}
</script>
Important
Don’t copy and paste the code shown above — it’s just sample code we’ve provided to help you understand the approach.
Next, add the Privacy Controls and Cookie Solution snippet, invoking the onReady callback:
<script type="text/javascript">
var _iub = _iub || [];
_iub.csConfiguration = {
"lang": "en",
"siteId": XXXXXX, // use your siteId
"cookiePolicyId": YYYYYY, // use your cookiePolicyId
"banner": {
"acceptButtonDisplay": true,
"customizeButtonDisplay": true,
"position": "float-top-center"
},
"callback": {
"onReady": function() {
if (typeof window.isConsentGivenByOtherPlatform === 'function' && isConsentGivenByOtherPlatform()) {
_iub.cs.api.setPreferences({
consent: true,
ccpa: true,
uspr: {
'all': true,
'sd8': true,
'sd9': true,
},
purposes: {
'1': true,
'2': true,
'3': true,
'4': true,
'5': true,
},
tcfv2: {
'all': true,
},
gac: {
'all': true,
},
}, true);
}
}
}
}
};
</script>
<script type="text/javascript">
// ask for 3rd party consent before including the CS
getConsentByOtherPlatform(function() {
var s = document.createElement('script');
s.src = '//cdn.iubenda.com/cs/iubenda_cs.js';
document.head.appendChild(s);
});
</script>
The onReady callback will check if consent is already given on another platform and, if so, stores it calling the _iub.cs.api.setPreferences() method.
Per-category consent
_iub.cs.api.storeConsent() allows to customize purposes too in the argument which can be {consent: true}, {consent: false} or {purposes: {1: true, 2: false, …}}.
_iub.cs.api.setPreferences(consentObj, hideBanner)
The _iub.cs.api.setPreferences method, expected two arguments: consentObj (required) and hideBanner (optional)
consentObj
It’s an object with follow preferences items:
- consent – required – accepts
trueorfalse– It refers to general consent - ccpa – required if CCPA is enabled – accepts
trueorfalse– it refers to US privacy and it will be applied only if CCPA is enabled in Cookie Solution - uspr – required if USPR is enabled – accepts an object with the following options – it refers to USPR consent and it will be applied only if USPR is enabled in Cookie Solution
- all – accepts
trueorfalse– this option sets the same value for all purposes
- all – accepts
uspr: {
all: true // or false
}
- [purposeId] – accepts
trueorfalse– this option sets the value for specific ID purposes
uspr: {
's': true, // or false
'sh': false, // or true
'adv': false // or true
}
- purposes – required if
perPurposeConsentis enabled – accepts an object with the following options – it refers to purposes consent and it will be applied only ifperPurposeConsentis enabled in Cookie Solution- all – accepts
trueorfalse– this option sets the same value for all purposes
- all – accepts
purposes: {
all: true // or false
}
- [purposeId] – accepts
trueorfalse– this option sets the value for specific ID purposes
purposes: {
'1': true, // or false
'2': false, // or true
'4': false // or true
}
- tcfv2 – required if TCF is enabled – accepts an object with the following options – it refers to TCF consent and it will be applied only if TCF is enabled in Cookie Solution
- all – accepts
trueorfalse– this option sets the same value for all TCF purposes
- all – accepts
tcfv2: {
all: true // or false
}
- [string] – accepts a TCF string
tcfv2: 'CP9rVEAP9rVEAB7FGCENAyEgAAAAAAAAAAAAAAAUHgJAA4AM-AjwBKoDfAHbAO5AgoBIgCSgEowJaATHAmSBNICfYFBAKDgAAAAA'
- gac – required if Google Aditional Consent is enabled – accepts an object with the following options – it refers to GAC consent and it will be applied only if GAC is enabled in Cookie Solution
- all – accepts
trueorfalse– this option sets the same value for all GAC vendors
- all – accepts
gac: {
all: true // or false
}
- [string] – accepts a GAC string
gac: '1~1584.2292.2392'
hideBanner
It’s a boolean to hide or not hide the banner after the preference storage, in this case, it should always be true
_iub.cs.api.setPreferences({ ... }, true); // hide the banner after the preference storage
_iub.cs.api.setPreferences({ ... }, false); // keep the banner after the preference storage