Web & AMP: Methods

Web & AMP: Methods

Web / AMP methods


CMP UI methods

The script adds the SibboCMP object globally. This object has the following methods:

init

Load the CMP configuration and check if the interface has to show up:
  1. SibboCMP.init(configuration); 

open

Show the CMP interface if it is hidden. The default view showed will be the Consent based on Purposes view. This will be the view to show when the user wants to edit its consents configuration:
  1. SibboCMP.open(); 

openBanner

Show the CMP initial banner:
  1. SibboCMP.openBanner();                                                                                                                                                     

openBannerIfNoTCS

Show the CMP initial banner when using the property of configuration bannerHidden: true if there is no consent string saved in Local storage nor in Cookies:
  1. SibboCMP.openBannerIfNoTCS();                                                                                                                                                     

isOpen

Returns true if CMP is visible and false if not:
  1. SibboCMP.isOpen();                                                                                                                                                     

openBanner

Returns true if CMP needs to refloat the initial banner and false if not, used when configuration property bannerHidden: true. Used with the methods open / openBanner / openBannerIfNoTCS:
  1. SibboCMP.initialBannerHasToRefloatCheck();                                                                                                                                                     

getActualView

Returns the name of the active view of the CMP: main, purposes, purposesLegInt, vendors, privacyPolicy, cookiesPolicy, privacyCookiesPolicy, termsAndConditions, additionalConsentProviders
  1. SibboCMP.getActualView();                                                                                                                                                     

getVendorList

Returns the vendor list as an object:
  1. SibboCMP.getVendorList();                                                                                                                                                     

tcsIsStoredinCookies

Returns true if the consent string (euconsent-v2) is stored in Cookies and false if not:
  1. SibboCMP.tcsIsStoredinCookies();                                                                                                                                                     

tcsIsStoredinLocalStorage

Returns true if the consent string (euconsent-v2) is stored in Local Storage and false if not:
  1. SibboCMP.tcsIsStoredinLocalStorage();                                                                                                                                                     


deleteDataInCookiesAndLocalStorage

Deletes al CMP data from both Cookies and Local Storage:
  1. SibboCMP.deleteDataInCookiesAndLocalStorage(true);
Deletes all CMP data from both Cookies and Local Storage but the data sibbo-uuid, the unique user id:
  1. SibboCMP.deleteDataInCookiesAndLocalStorage(false);  

close

Hide the CMP interface:
  1. SibboCMP.close();                                                                                                                                                     

destroy

Destroys the consent string and purpose settings stored in memory on execution, useful in some specific cases. If we want to refloat the CMP we will have to execute
SibboCMP.init(config) again:
  1. SibboCMP.destroy();

All these methods but SibboCMP.init can only be used after the CMP has been correctly initialised.



Methods to obtain consents

To obtain the consents we use the  __tcfapi method with various commands such as 'addEventListener', 'getVendorConsent', 'getOtherVendorConsents' as we will see next.
The old 'getTCData' command has been deprecated and 'addEventListener' should be used instead to get the consent string.
To get the user's consent string it is necessary to call the following command addEventListener:
  1. __tcfapi('addEventListener', 2, (tcData, success) => {

  2.   if(success) {

  3.     const consent = tcData.tcString;
  4.     console.log(consent);

  5.   } else {
  6.     console.error('Error: could not get addEventListener');

  7.   }

  8. });

To get the consent from a custom vendor, it is necessary to call the command getOtherVendorConsents:

To obtain consents from all vendors not included in IAB:
  1. __tcfapi("getOtherVendorConsents", 2, (otherVendorConsents, success) => {                                                   
  2.   if (success) {
  3.     console.log(otherVendorConsents);
  4.   } else {
  5.     console.error('Error: could not get otherVendorConsents')
  6.   }
  7. });

To obtain consent from a specific non-IAB vendor, you must use the cookieName property of the configuration to identify it.
Example for the vendor Cynapsis Interactive GmbH, its cookieName is cynapsisConsent:
  1. __tcfapi("getOtherVendorConsents", 2, (otherVendorConsents, success) => {                                                   
  2.   if (success) {
  3.     const cynapsis = otherVendorConsents.cynapsisConsent;
  4.     console.log(cynapsis);
  5.   } else {
  6.     console.error('Error: could not get otherVendorConsents')
  7.   }
  8. });


To get the consent from a specific IAB vendor, it is necessary to call the command getVendorConsent with the vendor Id (idVendor) as a parameter. The output is true if the vendor has been consented by the user and the vendors purposes, and special features (if it apply) has been accepted, or false if any of these items has been rejected:
  1. __tcfapi("getVendorConsent", 2, (vendorConsent, success) => {                                                                         
  2.   if (success) {
  3.     console.log(vendorConsent);
  4.   } else {
  5.     console.error('Error: could not get getVendorConsent');
  6.   }
  7. }, idVendor);


To check if Google can serve advertising, you have to call the isGoogleAccepted command. Returns true if advertising can be served or false otherwise:
  1. __tcfapi("isGoogleAccepted", 2, (googleConsent, success) => {                                                                          
  2.   if (success) {
  3.     console.log(googleConsent);
  4.   } else {
  5.     console.error('Error: could not get isGoogleAccepted');
  6.   }
  7. });


To get Google's additional consent string (AC string), which contains a list of consented Google Ad Tech Providers that are not registered with IAB, you have to call the getAddtlconsent command.
  1. __tcfapi("getAddtlconsent", 2, (addtlconsent, success) => {                                                                          
  2.   if (success) {
  3.     console.log(addtlconsent);
  4.   } else {
  5.     console.error('Error: could not get addtlconsent');
  6.   }
  7. });


Check if all purposes have been accepted (personalised command for SIBBO CMP)

This method can only be used if vendors have been defined in the configuration.
In order to check if all purposes have been accepted, call the command isAllAccepted. It returns true or false.
  1. __tcfapi("isAllAccepted", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. });


Check if selected purposes and vendors have been accepted (personalised command for SIBBO CMP)

In order to check if selected purposes and vendors have been accepted, call the command isAllAcceptedCustom. It returns true or false.
You need to specify the purposes and the vendors with arrays separated by commas, the order of the arrays is following:

Array with purposes based on consent,
array with purposes based on legitimate interest,
array with publisher purposes based on consent,
array with publisher purposes based on legitimate interest,
array with publisher custom purposes,
array with special features,
array with vendors based on consent,
array with vendors based on legitimate interest

There must be 8 arrays, some can be empty arrays.

The following example checks the acceptance of 10 purposes based on consent, 1 purpose based on legitimate interest, 10 publisher purposes based on consent, publisher purpose based on legitimate interest, 1 special feature
  1. __tcfapi("isAllAcceptedCustom", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. }, [1,2,3,4,5,6,7,8,9,10], [2], [1,2,3,4,5,6,7,8,9,10], [2], [], [1], [], [] );

The following example checks the acceptance of 14 vendors based on consent
  1. __tcfapi("isAllAcceptedCustom", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. }, [], [], [], [], [], [], [21, 32, 50, 77, 115, 126, 278, 284, 373, 531, 653, 755, 812, 1126], [] );

The following example checks the acceptance of 4 purposes based on consentpublisher custom purposes, 73 vendors based on legitimate interest
  1. __tcfapi("isAllAcceptedCustom", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. }, [8,9,10,11], [], [], [], [1], [], [], [1,2,4,6,8,10,11,12,13,14,15,16,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,36,37,39,40,42,44,45,46,47,48,49,50,52,53,55,56,57,58,59,60,61,62,66,69,70,71,73,75,76,77,78,80,82,83,84,85,87,90,91,92,93,94,95,97,98,100] );


Obtaining consents examples

All the information generated by the CMP is stored in the tcData object of the addEventListener command. Below are some examples of the type of information that can be obtained:

To get the consent of a purpose (e.g. purpose with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                      

  2.   if(success) {

  3.     const consent = tcData.purpose.consents[10];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a purpose based on legitimate interest (e.g. purpose with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                      

  2.   if(success) {

  3.     const consent = tcData.purpose.legitimateInterests[10];
  4.     console.log(consent);

  5.   }

  6. });

To get the consent of a vendor's purpose (e.g. vendor with ID 565):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                     

  2.   if(success) {

  3.     const consent = tcData.vendor.consents[565];
  4.     console.log(consent);

  5.  }

  6. });



To get the consent of a vendor's purpose based on legitimate interest (e.g. vendor with ID 565):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.vendor.legitimateInterests[565];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a publisher's purpose (e.g. publisher's purpose with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.consents[10];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a publisher's purpose based on legitimate interest (e.g. publisher's purpose based on legitimate interest with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.legitimateInterests[10];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a publisher's custom purpose (e.g. publisher's custom purpose with ID 1):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.customPurpose.consents[1];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a publisher's custom purpose based on legitimate interest (e.g. publisher's custom purpose based on legitimate interest with ID 1):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.customPurpose.legitimateInterests[1];
  4.     console.log(consent);

  5.   }

  6. });

To get the consent of a special feature (e.g. special feature with ID 1):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.specialFeatureOptins[1];
  4.     console.log(consent);

  5.   }

  6. });

Superfast Web methods


CMP UI methods

The sibbo-cmp-loader.js file adds the SibboCMPLoader object globally. This object has the following methods:

init

Load all the configuration and check if the interface has to be displayed:
  1. SibboCMPLoader.init( url core, url configuración )                                                                                                                                                     

openCmpConfig

Refloats the CMP if it is hidden. The default view that it will show will be the purpose view. Useful when the user wants to edit their consent:
  1. SibboCMPLoader.openCmpConfig(true)
openCmpConfig can only be used after the CMP has been successfully initialized.                


Methods to obtain consents

To obtain the consents we use the  __tcfapi method with various commands such as 'addEventListener', 'getVendorConsents', 'getOtherVendorConsents' as we will see next.
The old 'getTCData' command has been deprecated and 'addEventListener' should be used instead to get the consent string.

If you are using the Superfast CMP for Web you will need to ensure that the sibbo-cmp-loader.js file has finished executing before you can use the following __tcfapi methods.

There are two ways to do it:
  1. Execute these methods within the onContentLoaded function, see Technical Guide for the implementation of the CMP
  2. Use an event listener that waits for the 'sibbo-loader-init' event and upon receiving it executes the __tcfapi method, example:
  1. function initProgrammatic() {

  2.      // fire __tcfapi here
  3.             
  4.      document.removeEventListener('sibbo-loader-init', initProgrammatic);

  5.  }

  6. document.addEventListener('sibbo-loader-init', initProgrammatic);

To get the user's consent string it is necessary to call the following command addEventListener:
  1. __tcfapi('addEventListener', 2, (tcData, success) => {

  2.   if(success) {

  3.     const consent = tcData.tcString;
  4.     console.log(consent);

  5.   } else {
  6.     console.error('Error: could not get addEventListener');

  7.   }

  8. });



How to get the consent from CUSTOM VENDORS NOT INCLUDED IN IAB (personalised command for SIBBO CMP)
To get the consent from a custom vendor, it is necessary to call the command getOtherVendorConsents:
  1. __tcfapi("getOtherVendorConsents", 2, (otherVendorConsents, success) => {                                                   
  2.   if (success) {
  3.     console.log(otherVendorConsents);
  4.     //Example Twitter consent
  5.     const twitterConsent = otherVendorConsents.twitter;
  6.   } else {
  7.     console.error('Error: could not get otherVendorConsents');
  8.   }
  9. });

To get the consent from a specific IAB vendor, it is necessary to call the command getVendorConsent with the vendor Id (idVendor) as a parameter. The output is true if the vendor has been consented by the user or false if it has not been consented:
  1. __tcfapi("getVendorConsent", 2, (vendorConsent, success) => {                                                                         
  2.   if (success) {
  3.     console.log(vendorConsent);
  4.   } else {
  5.     console.error('Error: could not get getVendorConsent');
  6.   }
  7. }, idVendor);


To check if Google can serve advertising, you have to call the isGoogleAccepted command. Returns true if advertising can be served or false otherwise:
  1. __tcfapi("isGoogleAccepted", 2, (googleConsent, success) => {                                                                          
  2.   if (success) {
  3.     console.log(googleConsent);
  4.   } else {
  5.     console.error('Error: could not get isGoogleAccepted');
  6.   }
  7. });


To get Google's additional consent string (AC string), which contains a list of consented Google Ad Tech Providers that are not registered with IAB, you have to call the getAddtlconsent command.
  1. __tcfapi("getAddtlconsent", 2, (addtlconsent, success) => {                                                                          
  2.   if (success) {
  3.     console.log(addtlconsent);
  4.   } else {
  5.     console.error('Error: could not get addtlconsent');
  6.   }
  7. });


Check if all purposes have been accepted (personalised command for SIBBO CMP)

In order to check if all purposes have been accepted, call the command isAllAccepted. It returns true or false.
  1. __tcfapi("isAllAccepted", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. });


Check if selected purposes and vendors have been accepted (personalised command for SIBBO CMP)

In order to check if selected purposes and vendors have been accepted, call the command isAllAcceptedCustom. It returns true or false.
You need to specify the purposes and the vendors with arrays separated by commas, the order of the arrays is following:

Array with purposes based on consent,
array with purposes based on legitimate interest,
array with publisher purposes based on consent,
array with publisher purposes based on legitimate interest,
array with publisher custom purposes,
array with special features,
array with vendors based on consent,
array with vendors based on legitimate interest

There must be 8 arrays, some can be empty arrays.

The following example checks the acceptance of 10 purposes based on consent, 1 purpose based on legitimate interest, 10 publisher purposes based on consent, 1 publisher purpose based on legitimate interest, 1 special feature
  1. __tcfapi("isAllAcceptedCustom", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. }, [1,2,3,4,5,6,7,8,9,10], [2], [1,2,3,4,5,6,7,8,9,10], [2], [], [1], [], [] );

The following example checks the acceptance of 14 vendors based on consent
  1. __tcfapi("isAllAcceptedCustom", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. }, [], [], [], [], [], [], [21, 32, 50, 77, 115, 126, 278, 284, 373, 531, 653, 755, 812, 1126], [] );

The following example checks the acceptance of 4 purposes based on consent, 1 publisher custom purposes, 73 vendors based on legitimate interest
  1. __tcfapi("isAllAcceptedCustom", 2, (isAllAccepted, success) => {                                                                                    
  2.   if (success) {
  3.     console.log(isAllAccepted);
  4.   } else {
  5.     console.error('Error: could not get isAllAccepted');
  6.   }
  7. }, [8,9,10,11], [], [], [], [1], [], [], [1,2,4,6,8,10,11,12,13,14,15,16,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,36,37,39,40,42,44,45,46,47,48,49,50,52,53,55,56,57,58,59,60,61,62,66,69,70,71,73,75,76,77,78,80,82,83,84,85,87,90,91,92,93,94,95,97,98,100] );



Obtaining consents examples

All the information generated by the CMP is stored in the tcData object of the addEventListener command. Below are some examples of the type of information that can be obtained:

To get the consent of a purpose (e.g. purpose with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                      

  2.   if(success) {

  3.     const consent = tcData.purpose.consents[10];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a purpose based on legitimate interest (e.g. purpose with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                      

  2.   if(success) {

  3.     const consent = tcData.purpose.legitimateInterests[10];
  4.     console.log(consent);

  5.   }

  6. });


To get the consent of a vendor's purpose (e.g. vendor with ID 565):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                     

  2.   if(success) {

  3.     const consent = tcData.vendor.consents[565];
  4.     console.log(consent);

  5.  }

  6. });



To get the consent of a vendor's purpose based on legitimate interest (e.g. vendor with ID 565):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.vendor.legitimateInterests[565];
  4.     console.log(consent);

  5.   }

  6. });


To get the consent of a publisher's purpose (e.g. publisher's purpose with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.consents[10];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a publisher's purpose based on legitimate interest (e.g. publisher's purpose based on legitimate interest with ID 10):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.legitimateInterests[10];
  4.     console.log(consent);

  5.   }

  6. });



To get the consent of a publisher's custom purpose (e.g. publisher's custom purpose with ID 1):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.customPurpose.consents[1];
  4.     console.log(consent);

  5.   }

  6. });

To get the consent of a publisher's custom purpose based on legitimate interest (e.g. publisher's custom purpose based on legitimate interest with ID 1):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.publisher.customPurpose.legitimateInterests[1];
  4.     console.log(consent);

  5.   }

  6. });

To get the consent of a special feature (e.g. special feature with ID 1):
  1. __tcfapi('addEventListener', 2, (tcData, success) => {                                                                                                    

  2.   if(success) {

  3.     const consent = tcData.specialFeatureOptins[1];
  4.     console.log(consent);

  5.   }

  6. });


Methods for consentStatusHelper

Starting in V24.02, New methods for consentStatusHelper are available.  They have the same name as ConsentHelper methods changing "is" by "get".

  1. getConsentPurposeVendorStatus(2)