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).
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>
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.
_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, …}}
.
Before embedding the Privacy Controls and Cookie Solution code you’ll need to define a function that:
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>
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 on
Ready 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.
_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, …}}
.
The _iub.cs.api.setPreferences
method, expected two arguments: consentObj (required) and hideBanner (optional)
It’s an object with follow preferences items:
true
or false
– It refers to general consenttrue
or false
– it refers to US privacy and it will be applied only if CCPA is enabled in Cookie Solutiontrue
or false
– this option sets the same value for all purposesuspr: { all: true // or false }
true
or false
– this option sets the value for specific ID purposesuspr: { 's': true, // or false 'sh': false, // or true 'adv': false // or true }
perPurposeConsent
is enabled – accepts an object with the following options – it refers to purposes consent and it will be applied only if perPurposeConsent
is enabled in Cookie Solution
true
or false
– this option sets the same value for all purposespurposes: { all: true // or false }
true
or false
– this option sets the value for specific ID purposespurposes: { '1': true, // or false '2': false, // or true '4': false // or true }
true
or false
– this option sets the same value for all TCF purposestcfv2: { all: true // or false }
tcfv2: 'CP9rVEAP9rVEAB7FGCENAyEgAAAAAAAAAAAAAAAUHgJAA4AM-AjwBKoDfAHbAO5AgoBIgCSgEowJaATHAmSBNICfYFBAKDgAAAAA'
true
or false
– this option sets the same value for all GAC vendorsgac: { all: true // or false }
gac: '1~1584.2292.2392'
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