Load notice by ID

This section describes how to configure the Didomi consent notice through its programmatic API and the window.didomiConfig object.

Most configuration options are available through the Didomi Console and this documentation only applies to edge cases or custom implementations that require it.

When using the Embed Code provided in the Didomi Console, the notice configuration is determined by matching the domain name of the website with the domains configured in the notice.

Default Embed Code

This works well for most use cases but does not allow granularly deciding what notice configuration should be loaded on a website. In particular, it does not allow loading different consent notices on a single domain based on variables (path, query-string parameters, etc.).

You can bypass domain targeting and decide what consent notice to embed on a given webpage by using the following Embed Code instead of the one found in the Didomi Console:

<script type="text/javascript">
window.gdprAppliesGlobally=true;(function(){function r(){if(!window.frames.__cmpLocator){if(document.body&&document.body.firstChild){var e=document.body;var t=document.createElement("iframe");t.style.display="none";t.name="__cmpLocator";t.title="cmpLocator";e.insertBefore(t,e.firstChild)}else{setTimeout(r,5)}}}function e(e,t,r){if(typeof r!=="function"){return}if(!window.__cmpBuffer){window.__cmpBuffer=[]}if(e==="ping"){r({gdprAppliesGlobally:window.gdprAppliesGlobally,cmpLoaded:false},true)}else{window.__cmpBuffer.push({command:e,parameter:t,callback:r})}}e.stub=true;function t(a){if(!window.__cmp||window.__cmp.stub!==true){return}if(!a.data){return}var n=typeof a.data==="string";var e;try{e=n?JSON.parse(a.data):a.data}catch(t){return}if(e.__cmpCall){var o=e.__cmpCall;window.__cmp(o.command,o.parameter,function(e,t){var r={__cmpReturn:{returnValue:e,success:t,callId:o.callId}};a.source.postMessage(n?JSON.stringify(r):r,"*")})}}if(typeof window.__cmp!=="function"){window.__cmp=e;if(window.addEventListener){window.addEventListener("message",t,false)}else{window.attachEvent("onmessage",t)}}r()})();(function(e,t){var r=document.createElement("script");r.id="spcloader";r.type="text/javascript";r.async=true;r.src="https://sdk.privacy-center.org/"+e+"/loader.js?target_type=notice&target="+t;r.charset="utf-8";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a)})("{{publicAPIKey}}","{{noticeId}}");
</script>

Make sure to replace the following variables in the code above:

  • {{publicAPIKey}}: Use the public API key available in your Didomi Console

  • {{noticeId}}: Use the notice ID available in your Didomi Console by looking at the URL when you are editing a consent notice (for instance, if your URL is https://console.didomi.io/didomi/widgets/notices/TQnRn8sr/embed, the notice ID is TQnRn8sr)