SmartTV & HbbTV: Methods

SmartTV & HbbTV: 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();                                                                                                                                                     

initialBannerHasToRefloatCheck

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);  

deleteDataFromDatabase

Deletes al CMP data from database related to deviceId, works only when save in database is active and deviceId is set ic configuration
  1. SibboCMP.deleteDataFromDatabase();


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.

To get the user's consent string it is necessary to call the following command addEventListener:
The old 'getTCData' command has been deprecated and 'addEventListener' should be used instead to get the consent string.
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                         

  2.   if(success) {

  3.     var 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:
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
To obtain consents from all vendors not included in IAB:
  1. __tcfapi("getOtherVendorConsents", 2, function(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, function(otherVendorConsents, success) {                                                   
  2.   if (success) {
  3.     var 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 or false if it has not been consented:
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi("getVendorConsent", 2, function(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:
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi("isGoogleAccepted", 2, function(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.
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi("isAllAccepted", 2, function(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 function. 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                      

  2.   if(success) {

  3.     var 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                      

  2.   if(success) {

  3.     var 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                     

  2.   if(success) {

  3.     var 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                    

  2.   if(success) {

  3.     var 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                    

  2.   if(success) {

  3.     var 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                    

  2.   if(success) {

  3.     var 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                    

  2.   if(success) {

  3.     var 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):
The CMP is running on a TV device, you cannot use javascript ES6: arrow functions, const, let, etc. You must use javascript ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                    

  2.   if(success) {

  3.     var 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):
El CMP se ejecuta en un dispositivo de TV, no se puede usar javascript ES6: funciones flecha, const, let, etc. Se debe usar ES5.
  1. __tcfapi('addEventListener', 2, function(tcData, success) {                                                                                                    

  2.   if(success) {

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

  5.   }

  6. });