Before loading partners scripts on your site, you must verify that user has given consent or hasn't objected to the legitimate interest.
With the addEventListener command, you can register a listener to the CMP that will be called with the TC Data whenever an event occurs. When adding a listener, the callback is called immediately with the current TC Data as well as a listenerId that you must store if you need to remove the listener.
window.__tcfapi("addEventListener",2,function (tcData, success) {if (success && tcData && (tcData.eventStatus =="cmpuiclosed"||tcData.eventStatus =="tcloaded")) {if (!tcData.gdprApplies) {console.log("GDPR doesn't apply to user"); } else {if (tcData.vendor.consents[53] &&tcData.purpose.consents[1]) {console.log("Vendor ID 53 has consent for purpose ID 1"); }if (!tcData.vendor.consents[53] ||!tcData.purpose.consents[2]) {console.log("Vendor ID 53 has no consent for purpose ID 2"); }if (tcData.vendor.legitimateInterests[53] &&tcData.purpose.legitimateInterests[9]) {console.log("User has been informed of vendor ID 53's legitimate interest for purpose ID 9 and hasn't objected to it"); }if (!tcData.vendor.legitimateInterests[53] ||!tcData.purpose.legitimateInterests[10]) {console.log("User has objected to vendor ID 53's legitimate interest for purpose ID 10"); } } }});
You can specify a list of vendor IDs for which the TC Data is requested.
window.__tcfapi("addEventListener",2,function (tcData, success) {if (success && tcData && (tcData.eventStatus =="cmpuiclosed"||tcData.eventStatus =="tcloaded")) {if (!tcData.gdprApplies) {console.log("GDPR doesn't apply to user"); } else {if (tcData.vendor.consents[53] &&tcData.purpose.consents[1]) {console.log('Vendor ID 53 has consent for purpose ID1'); }if (tcData.vendor.consents[100] &&tcData.purpose.consents[1]) {// This will never happen since vendor ID 100 is not// included in the vendorIDs parameter console.log('Vendor ID 53 has consent for purpose ID 1'); } } }}, [4, 10, 53]);
Read the Global Vendor List
The Global Vendor List containing the purposes and vendors participating in the Transparency & Consent Framework can be retrieved with the getVendorList command.