Links

Widget

Openli provides you with an easy and straightforward approach to collect and manage consent. We have a few widgets that do just that!

Setup

The legal.js widget library requires a small snippet of JavaScript code to be included once in each page you use it on. This snippet is available in your account's Widgets section, and looks like this:
<script>
!function(){var i,e,t,s=window.legal=window.legal||[];if(s.SNIPPET_VERSION="3.0.0",i="https://widgets.legalmonster.com/v1/legal.js",!s.__VERSION__)if(s.invoked)window.console&&console.info&&console.info("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 e=Array.prototype.slice.call(arguments);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)}}}();
</script>
Whenever possible, you should include the snippet as the first script in your page's <head> section:
<!doctype html>
<html>
<head>
...
<script>
!function(){var i,e,t,s=window.legal=window.legal||[];if(s.SNIPPET_VERSION="3.0.0",i="https://widgets.legalmonster.com/v1/legal.js",!s.__VERSION__)if(s.invoked)window.console&&console.info&&console.info("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 e=Array.prototype.slice.call(arguments);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)}}}();
</script>
...
</head>
<body>
...
</body>
</html>

What's next?

When you have legal.js loaded, you can begin to use its functionality to collect consents, show your legal agreements, and update user-data.

General widget options

Identify a known user

Openli gives you the ability to identify your users more precisely using a unique value that your internal system already associates with them. Identifying a user this way allow us to be certain who the user is, and not to rely on cookies, which the user can change or delete.
To do this, You can provide thelegal.widget() method with a value for the identifier option.
Here is an example of identifying your user when initializing a widget:
legal.widget({
type: "<<WIDGET TYPE>>",
widgetPublicKey: "<<WIDGET PUBLIC KEY>>",
identifier: "<<USER ID>>",
});
In the above example, <<USER ID>> is what you will substitute with your unique identifier for the user.
We recommend using database IDs because they tend to remain consistent over time. This helps to ensure that you can still recognize the same user in all of your analytics tools even though the user's other details might change.

Set the widget language

To set the display language, initialise your widget with the locale option set to the value for the language you desire. For example, to use Danish when the jurisdiction is Denmark, your widget's initialisation would look similar to this:
legal.widget({
type: "...",
widgetPublicKey: "...",
locale: "da-dk",
});
English is the default language, and supported languages are listed below.
If you do not specify a language, or if the language you set is not supported by us in the visitor's jurisdiction, English will be used. The table below lists the supported combinations.
Language
Supported in jurisdiction
Option value
English (EN)
All jurisdictions
None, or en-us
Danish (DA)
Denmark (DK)
da-dk
Dutch (NL)
Netherlands (NL)
nl-nl
English (EN)
Great Britain (GB)
en-gb
English (EN)
United States (US)
en-us
French (FR)
France (FR)
fr-fr
German (DE)
Austria (AT)
de-at
German (DE)
Germany (DE)
de-de
Norwegian (NO)
Norway (NO)
no-no
Swedish (SV)
Sweden (SE)
sv-se