Getting started

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

Legal.js is currently in beta

Install legal.js

This JavaScript snippet loads the legal.js library asynchronously and initialises it with the specific project and related data.

Just copy and paste the JavaScript shown below into the header of your web page:

<script>
!function(){var r,e,n,s=window.legal=window.legal||[];if(s.SNIPPET_VERSION="1.2.5",r="https://widgets.legalmonster.com/v1/legal.js",!s.__VERSION__)if(s.invoked)window.console&&console.error&&console.error("Legal.js snippet included twice on page.");else{for(s.invoked=!0,s.methods=["document","signup","user","ensureConsent","enableImpliedConsent"],s.factory=function(n){return function(){var e=Array.prototype.slice.call(arguments);return e.unshift(n),s.push(e),s}},e=0;e<s.methods.length;e++)n=s.methods[e],s[n]=s.factory(n);s.load=function(e,n){var t,o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=r,(t=document.getElementsByTagName("script")[0]).parentNode.insertBefore(o,t),s.__project=e,s.__loadOptions=n||{}}}}();
legal.load("<<PROJECT PUBLIC KEY>>");
// At this point, you can make further calls on the legal object
</script>

Substitute the placeholder <<PROJECT PUBLIC KEY>> with the actual key of the Legal Monster project that you are currently working with. You can find your public key here.

You are now ready to use the widgets.

You can add additional functionality to the widget. Add functions either by adding specific lines to the above snippet directly after legal.load("<<PROJECT PUBLIC KEY>>"); or simply add the code to another<script> tag on your page. Any further calls to the library must be after the above installation snippet.

Important note: you should call legal.load(...) only once per page-load. Calling it multiple times is currently unsupported. If you need to re-initialize a widget, for example when re-rendering a form, you should only make an additional call to the specific functionality you need, such as legal.signup(...).

Load options

Identify user

Legal Monster gives you the ability to specify and identify users more precisely. You can provide thelegal.load() method with the identifier parameter in an options object. Identifying a user this way allow us to be certain who the user is and not only rely on cookies, which the user can clear or delete.

Here is an example of identifying your user when initializing with legal.load():

<script>
!function(){var r,e,n,s=window.legal=window.legal||[];if(s.SNIPPET_VERSION="1.2.5",r="https://widgets.legalmonster.com/v1/legal.js",!s.__VERSION__)if(s.invoked)window.console&&console.error&&console.error("Legal.js snippet included twice on page.");else{for(s.invoked=!0,s.methods=["document","signup","user","ensureConsent","enableImpliedConsent"],s.factory=function(n){return function(){var e=Array.prototype.slice.call(arguments);return e.unshift(n),s.push(e),s}},e=0;e<s.methods.length;e++)n=s.methods[e],s[n]=s.factory(n);s.load=function(e,n){var t,o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=r,(t=document.getElementsByTagName("script")[0]).parentNode.insertBefore(o,t),s.__project=e,s.__loadOptions=n||{}}}}();
legal.load("<<PROJECT PUBLIC KEY>>", {
identifier: "<<USER ID>>",
});
</script>

In the above snippet, <<USER ID>> refers to a value that you substitute with a 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 recognise them as the same user in all of your analytics tools even though the user might change their credentials.

Set language

You can also change the display language of legal.js when you load it. Language is set with the locale parameter in an options object in legal.load():

<script>
!function(){var r,e,n,s=window.legal=window.legal||[];if(s.SNIPPET_VERSION="1.2.5",r="https://widgets.legalmonster.com/v1/legal.js",!s.__VERSION__)if(s.invoked)window.console&&console.error&&console.error("Legal.js snippet included twice on page.");else{for(s.invoked=!0,s.methods=["document","signup","user","ensureConsent","enableImpliedConsent"],s.factory=function(n){return function(){var e=Array.prototype.slice.call(arguments);return e.unshift(n),s.push(e),s}},e=0;e<s.methods.length;e++)n=s.methods[e],s[n]=s.factory(n);s.load=function(e,n){var t,o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=r,(t=document.getElementsByTagName("script")[0]).parentNode.insertBefore(o,t),s.__project=e,s.__loadOptions=n||{}}}}();
legal.load("<<PROJECT PUBLIC KEY>>", {
locale: "da-dk",
});
</script>

Currently supported languages are Danish (da-dk) and English (en-us). English is the default.