UniConsent Tag for Web

UniConsent Tag Installation and Setup

Each of your websites has a unique javascript tag to be installed on every page.

You can find the UniConsent tag at the Install & Setup section.

There are two parts of the tags. The first part is a stub that should be embedded at the top of your page. The second part can be loaded with async. There is a minimum performance impact on your site.

Stub codes

You can also choose to load the stub code with the following javascript tag:

<script src="https://cmp.uniconsent.com/v2/stub.min.js"></script>

You can also replace the following code with the above stub tag to improve page speed:

<script type="text/javascript">
!function(){var i,r,o;i="__tcfapiLocator",r=[],(o=window.frames[i])||(function e(){var t=window.document,a=!!o;if(!a)if(t.body){var n=t.createElement("iframe");n.style.cssText="display:none",n.name=i,t.body.appendChild(n)}else setTimeout(e,50);return!a}(),window.__tcfapi=function(){for(var e,t=[],a=0;a<arguments.length;a++)t[a]=arguments[a];if(!t.length)return r;if("setGdprApplies"===t[0])3<t.length&&2===parseInt(t[1],10)&&"boolean"==typeof t[3]&&(e=t[3],"function"==typeof t[2]&&t[2]("set",!0));else if("ping"===t[0]){var n={gdprApplies:e,cmpLoaded:!1,cmpStatus:"stub"};"function"==typeof t[2]&&t[2](n,!0)}else r.push(t)},window.addEventListener("message",function(n){var i="string"==typeof n.data,e={};try{e=i?JSON.parse(n.data):n.data}catch(e){}var r=e.__tcfapiCall;r&&window.__tcfapi(r.command,r.version,function(e,t){var a={__tcfapiReturn:{returnValue:e,success:t,callId:r.callId}};i&&(a=JSON.stringify(a)),n.source.postMessage(a,"*")},r.parameter)},!1))}();
!function(){var i,n,s;i="__uspapiLocator",n=[],(s=window.frames[i])||(function a(){var e=window.document,n=!!s;if(!s)if(e.body){var t=e.createElement("iframe");t.style.cssText="display:none",t.name=i,e.body.appendChild(t)}else setTimeout(a,50);return!n}(),window.__uspapi=function(){for(var a=[],e=0;e<arguments.length;e++)a[e]=arguments[e];if(!a.length)return n;"ping"===a[0]?"function"==typeof a[2]&&a[2]({cmpLoaded:!1,cmpStatus:"stub"},!0):n.push(a)},window.addEventListener("message",function(t){var i="string"==typeof t.data,a={};try{a=i?JSON.parse(t.data):t.data}catch(a){}var s=a.__uspapiCall;s&&window.__uspapi(s.command,s.version,function(a,e){var n={__uspapiReturn:{returnValue:a,success:e,callId:s.callId}};i&&(n=JSON.stringify(n)),t.source.postMessage(n,"*")},s.parameter)},!1))}();
window.__gpp_addFrame=function(e){if(!window.frames[e])if(document.body){var t=document.createElement("iframe");t.style.cssText="display:none",t.name=e,document.body.appendChild(t)}else window.setTimeout(window.__gpp_addFrame,50,e)},window.__gpp_stub=function(){var e=arguments;if(__gpp.queue=__gpp.queue||[],__gpp.events=__gpp.events||[],!e.length||1==e.length&&"queue"==e[0])return __gpp.queue;if(1==e.length&&"events"==e[0])return __gpp.events;var t=e[0],p=1<e.length?e[1]:null,s=2<e.length?e[2]:null;if("ping"===t)p&&p({gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[-1],gppString:"",parsedSections:{}},!0);else if("addEventListener"===t){"lastId"in __gpp||(__gpp.lastId=0),__gpp.lastId++;var n=__gpp.lastId;__gpp.events.push({id:n,callback:p,parameter:s}),p({eventName:"listenerRegistered",listenerId:n,data:!0,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[-1],gppString:"",parsedSections:{}}},!0)}else if("removeEventListener"===t){for(var a=!1,i=0;i<__gpp.events.length;i++)if(__gpp.events[i].id==s){__gpp.events.splice(i,1),a=!0;break}p({eventName:"listenerRemoved",listenerId:s,data:a,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[-1],gppString:"",parsedSections:{}}},!0)}else"hasSection"===t?p(!1,!0):"getSection"===t||"getField"===t?p(null,!0):__gpp.queue.push([].slice.apply(e))},window.__gpp_msghandler=function(s){var n="string"==typeof s.data;try{var t=n?JSON.parse(s.data):s.data}catch(e){t=null}if("object"==typeof t&&null!==t&&"__gppCall"in t){var a=t.__gppCall;window.__gpp(a.command,function(e,t){var p={__gppReturn:{returnValue:e,success:t,callId:a.callId}};s.source.postMessage(n?JSON.stringify(p):p,"*")},"parameter"in a?a.parameter:null,"version"in a?a.version:"1.1")}},"__gpp"in window&&"function"==typeof window.__gpp||(window.__gpp=window.__gpp_stub,window.addEventListener("message",window.__gpp_msghandler,!1),window.__gpp_addFrame("__gppLocator"));
</script>

The above stub code or tag support the following API: IAB TCF API, IAB GPP API, IAB USP API.

You can add this at the top of your pages if you are not using Google Tag Manager but like to enable Consent Mode V2:

<script src="https://cmp.uniconsent.com/v2/stubgcm.min.js"></script>

or add the following code at the top of your pages:

<script>
window.gtag||(window.dataLayer=window.dataLayer||[],window.gtag=function(){window.dataLayer.push(arguments)}),window.gtag("set","developer_id.dZTcxZD",!0),window.gtag("consent","default",{ad_storage:"denied",functionality_storage:"denied",personalization_storage:"denied",analytics_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",security_storage:"granted",wait_for_update:3e3}),window.gtag("set","ads_data_redaction",!0),window.gtag("set","url_passthrough",!1);
</script>

Find more about Google Consent Mode setup at https://www.uniconsent.com/docs/tutorials/google-consent-mode

You can disable 'privacy badge' and add the following link on your page.

<a href="#" onclick='__unicapi("openunic");return false;'>Consent Settings</a>

You can target a DIV on your web pages with CSS selector, UniConsent automatically insert the Consent Settings Link within the DIV based on GEO location and your enabled features.

<div id="uniconsent-config"></div>

You can put the following place holder DIV at footer of your web pages, UniConsent automatically insert the Consent Settings Link within the place holder based on GEO location and your enabled features.

<div id="uniconsent-config"></div>

Install with WordPress and Drupal plugin:

You can find the license key at the Install & Setup section.

For Wordpress WP Rocket users

You have to excluding inline JavaScript from combine:

  1. Log in to your WordPress Admin dashboard > Settings > WP Rocket.
  2. Click the File Optimization tab, and scroll down to the JavaScript Files section.
  3. Minify JavaScript files > Exclude JavaScript Files: Enter cmp.uniconsent.com.

For Cloudflare Rocket Loader users

You must add data-cfasync="false" to the scripts:

<script data-cfasync="false" src="https://cmp.uniconsent.com/v2/stub.min.js"></script>

and

<script data-cfasync="false" async src='https://cmp.uniconsent.com/v2/YOUR_ID/cmp.js'></script>

Install via Google Tag Manager

You can find instructions about how to install UniConsent via Google Tag Manager at https://www.uniconsent.com/docs/tutorials/gtm-integration.

Next

If you like to integrate your third party javascript tags, please go to Thrid party Javascript Tags Integration section.

Verify the Setup

You can monitor the developer console for warning messages or use the UniConsent Consent Validator to ensure that Consent Mode, IAB TCF, and IAB GPP data are available and correctly passing on your webpages.

Regularly check the implementation audit status on your dashboard.

  1. Google Consent Mode Enabled, but Default Status Stub Code is Missing

    Issue: You might encounter an error message in the Validator or developer console:

    Error: Consent Mode Default Status is not added.

    Solution: Add the Default Status stub code at the top of your pages to resolve this issue. You can follow the instructions here: Consent Mode Default Status Tag Installation.

  2. Google Consent Mode Enabled, but Default Status Stub Code is Added After Google Tags

    Issue: If the Default Status stub code is added after your Google tags, you may see the following error message in the Validator or developer console:

    Error: Your Google tags are loaded before Consent Mode Default Status and CMP.

    Solution: Ensure the Default Status stub code is added at the very top of your pages, before any Google tags. Follow the guide here: Consent Mode Default Status Tag Installation.

  3. Google Consent Mode Enabled via Google Tag Manager, but Not All Google Tags Are Managed in Google Tag Manager

    Issue: When some Google tags are not managed in Google Tag Manager, you might see errors similar to those described above.

    Solution: Either add the Default Status stub code at the top of your pages or ensure all your Google tags are managed within Google Tag Manager. Refer to the guide: Consent Mode Default Status Tag Installation.

  4. IAB TCF Stub Code is Missing

    Issue: The IAB TCF stub code is not included, leading to potential errors.

    Solution: Add the IAB TCF stub code at the top of your pages. Follow the instructions here: Stub Codes Installation.

  5. IAB GPP Stub Code is Missing

    Issue: The IAB GPP stub code is missing from your implementation.

    Solution: Include the IAB GPP stub code at the top of your pages. You can find the relevant guide here: Stub Codes Installation.

  6. USP API Stub Code is Missing

    Issue: The IAB USP stub code is not present.

    Solution: To resolve this, add the IAB USP stub code at the top of your pages. Detailed instructions are available here: Stub Codes Installation.