PubConsent

Web Standard Integration

6min
once you've opened and configured your cmp, in the integration tab, you'll find instructions to add pubconsent cmp to your site in just a few simple clicks for integration, make sure to follow the instructions and do not modify the integration code provided in the panel, as the integration code ensures cross browser support of the cmp and performance improvements specific to the user's browser be careful to avoid duplicates of the cmp script tag to offer users a better experience, we recommend placing the cmp script tag inside the tag and as close to the top as possible follow our preconnect & priorities docid 3rhxhkjalnig 3qftalus t o improve integration and the experience of your users in addition to the integration code of the js code, you can configure a callback that is executed when a user gives or changes consent an example is provided below please note that the ccpa version will be available soon in the "onconsent" callback shown in the example, there are 3 input parameters consentdata an object that always contains the "privacylaw" field, which can be 'tcf v2 gdpr' or 'google consent mode' when the version is gdpr, it also contains tcstring, acstring, and pcstring, while when the version is google consent mode, it contains things relative to the google consent mode these strings represent the current state of the user's choices for each privacy law (later the field will be changed to cmptype since it's more appropriate) consentobject an object that contains additional information about consent when the privacy law is gdpr, there is information related to the iab framework, while when it is google consent mode, there is information related to gcm v2 publisherconsentobject an object that contains information about the user's choices regarding cookies (information not belonging to the iab framework) currently available only when gdpr privacy law applies to the user most publishers use the consentobject to verify the possibility of serving advertisements below is an example of a configuration with specific logic to check if certain iab purposes have been accepted by the user pubtech queue on consent push(function onconsent(cmptype, data) { const tcfdata = data consentbaseapi; const publisherconsentobject = data integrations cookieconsents; if (consentdata privacylaw == 'tcf v2 gdpr') { let purposerequired; const purposeidrequired = \[1,2,3,4,5,6,7,8,9,10,11]; purposeidrequired foreach(function start(id) { purposerequired = (tcfdata purposeconsents has(id) === true && purposerequired !== false) ? true false; }) if (purposerequired) { console log('cookie accepted'); } else { console log('cookie refused'); } console log(publisherconsentobject featurecookieschoice); //return true if is enabled console log(publisherconsentobject measurementcookieschoice); //return true if is enabled console log(publisherconsentobject userexperiencecookieschoice); //return true if is enabled } }); if purposerequired is true, then the user has accepted all 11 purposes with the specified ids additionally, as shown with the parameter publisherconsentobject, you can check for other types of cookies that are not related to advertising the complete list of purposes is available here be careful to avoid duplicates of the cmp script tag technical cookies are always enabled by definition, so you don't need to check any flag once the integration is complete, make sure to block third party codes from using the cookies you have configured, following the getting started docid\ xxtjtdrpzgzem2ziujagl integrate google consent mode v2 the integration of google consent mode v2 can be done through one of the two available integrations gtm integration (consent mode) docid\ msvncxayl6fiopafibw1e gtag integration (consent mode) docid\ rzcyddooh lgscux tia8