Collect cookie consent

The legal.js cookie-consent widget is under heavy development. It currently supports analytical, marketing, and necessary cookies; support for other categories will be added in future.


This guide assumes that you have successfully created your cookie-widget in the Openli app, and have its JavaScript snippet ready to integrate.

To collect cookie-consent with legal.js, you must embed the widget using its generated JavaScript snippet.

The snippet must be included immediately before the closing-tag of the body element, like this:

            !function(){var i,e,t,||[];if(s.SNIPPET_VERSION="3.0.0",i="",!s.__VERSION__)if(s.invoked)window.console&&"legal.js: The initialisation snippet is included more than once on this page, and does not need to be.");else{for(s.invoked=!0,s.methods=["cookieConsent","document","ensureConsent","handleWidget","signup","user"],s.factory=function(t){return function(){var;return e.unshift(t),s.push(e),s}},e=0;e<s.methods.length;e++)t=s.methods[e],s[t]=s.factory(t);s.load=function(e,t){var n,o=document.createElement("script");o.setAttribute("data-legalmonster","sven"),o.type="text/javascript",o.async=!0,o.src=i,(n=document.getElementsByTagName("script")[0]).parentNode.insertBefore(o,n),s.__project=e,s.__loadOptions=t||{}},s.widget=function(e){s.__project||s.load(e.widgetPublicKey),s.handleWidget(e)}}}();
                type: "cookie",
                widgetPublicKey: "Your cookie-consent widget's public-key",

If you are unable to do this, you must ensure that the call to legal.widget(...) occurs after the DOM is ready, using a combination of the DOMContentLoaded event and the document.readyState property. This reference article provides a good overview of the events involved. Contact us if you are in doubt.

Next steps

pageBlocking cookiespageCookie-widget options

Last updated