Se stai passando da un’altra soluzione di gestione dei cookie alla nostra, potresti voler migrare i consensi che hai già raccolto. Questo è utile per garantire che gli utenti che hanno già dato il loro consenso con la soluzione precedente non ricevano nuovamente il cookie banner e la relativa richiesta di consenso.
Ci sono due modi per farlo, a seconda che la “vecchia” piattaforma fornisca un cookie (metodo sincrono) o richieda una chiamata alla sua API (metodo asincrono).
Prima di incorporare Privacy Controls and Cookie Solution dovrai definire una funzione sincrona (ad esempio isConsentGivenByOtherPlatform
) per ottenere il consenso dall’altra piattaforma:
- <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>
Non copiare e incollare il codice mostrato qui sopra: è solo un esempio di codice che ti abbiamo fornito per aiutarti a capire l’approccio.
Successivamente, aggiungi il frammento Privacy Controls and Cookie Solution, richiamando il callback onReady
:
- <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>
Il callback onReady
controlla se il consenso è già stato dato su un’altra piattaforma e, in caso affermativo, lo memorizza chiamando il metodo _iub.cs.api.setPreferences()
.
_iub.cs.api.storeConsent()
permette di personalizzare anche gli scopi nell’argomento che può essere {consent: true}
, {consent: false}
o {purposes: {1: true, 2: false, …}}
.
Prima di incorporare il codice di Privacy Controls and Cookie Solution dovrai definire una funzione che:
Ecco un esempio:
- <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>
Non copiare e incollare il codice mostrato qui sopra: è solo un esempio di codice che ti abbiamo fornito per aiutarti a capire l’approccio.
Successivamente, aggiungi il frammento Privacy Controls and Cookie Solution, richiamando il callback on
Ready:
- <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>
Il callback onReady
controlla se il consenso è già stato dato su un’altra piattaforma e, in caso affermativo, lo memorizza chiamando il metodo _iub.cs.api.setPreferences()
.
_iub.cs.api.storeConsent()
permette di personalizzare anche gli scopi nell’argomento che può essere {consent: true}
, {consent: false}
o {purposes: {1: true, 2: false, …}}
.
Il metodo _iub.cs.api.setPreferences
prevede due argomenti: consentObj (obbligatorio) e hideBanner (opzionale).
Si tratta di un oggetto con le seguenti preferenze:
true
o false
– Si riferisce al consenso generaletrue
o false
– si riferisce alla privacy degli Stati Uniti e sarà applicato solo se il CCPA è abilitato in Cookie Solutiontrue
o false
– questa opzione imposta lo stesso valore per tutti gli scopi
- uspr: {
- all: true // or false
- }
true
o false
– questa opzione imposta il valore per scopi specifici dell’ID
- uspr: {
- 's': true, // or false
- 'sh': false, // or true
- 'adv': false // or true
- }
perPurposeConsent
è abilitato – accetta un oggetto con le seguenti opzioni – si riferisce al consenso per gli scopi e sarà applicato solo se perPurposeConsent
è abilitato nella Cookie Solution
true
o false
– questa opzione imposta lo stesso valore per tutti gli scopi
- purposes: {
- all: true // or false
- }
true
o false
– questa opzione imposta il valore per scopi specifici dell’ID
- purposes: {
- '1': true, // or false
- '2': false, // or true
- '4': false // or true
- }
true
o false
– questa opzione imposta lo stesso valore per tutti gli scopi TCF
- tcfv2: {
- all: true // or false
- }
- tcfv2: 'CP9rVEAP9rVEAB7FGCENAyEgAAAAAAAAAAAAAAAUHgJAA4AM-AjwBKoDfAHbAO5AgoBIgCSgEowJaATHAmSBNICfYFBAKDgAAAAA'
true
o false
– questa opzione imposta lo stesso valore per tutti i fornitori GAC
- gac: {
- all: true // or false
- }
- gac: '1~1584.2292.2392'
È un booleano che permette di nascondere o meno il banner dopo la memorizzazione delle preferenze. 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