Openli
IntroductionGetting StartedTechnical DocumentationGet help
  • Getting started
    • Introduction
    • Dictionary
    • FAQ
      • IAB TCF v2.0
  • Privacy hub
    • How to create your privacy profile
    • How can I get an Openli Privacy Badge?
    • Vendor owners
    • Why are custom properties on vendors super valuable?
    • Setting up custom properties
  • Tasks
  • Cookie Consent Management
    • Quickstart
    • Checklist: Cookies
    • Cookie widget
      • Create a cookie policy
      • Create a cookie widget
      • Install the widget
      • Manually add any cookies
      • Customise your widget
      • How to get color codes
      • Set the widget language
      • Use custom link/button instead of Cookie Shield
      • Add company name to cookie pop-up
    • Categorise your cookies
    • Adding information to cookies
    • Adding information to your cookie providers
    • Blocking Cookies with Openli
    • Cookie expiration dates and lifespan
      • Changing expiration on Google Analytics cookies
  • Policy and agreement management
    • Generate your privacy policy
    • Changing an old cookie policy to a new on autopilot
    • Embed your policies and legal agreements
      • Embedding agreements without displaying a widget
    • Install the Privacy Badge
  • General Openli guides
    • Setting up SSO (Single Sign-On)
      • SSO with Azure AD (Microsoft)
      • SSO with Google
      • SSO with Okta
      • How to log in with SSO
    • Add a website to your Openli account
    • Using projects to handle multiple languages
    • Collect consents without storing IP addresses or user-agents
  • Technical documentation
    • Widget
      • Collect cookie consent
        • Blocking cookies
        • Blocking embedded media
        • Cookie-widget options
        • Consent state API
    • API
      • Services
        • Personal data
        • Subprocessors
    • Cookies set by Openli
  • System Specific Integration Guides
    • Cloudflare
  • Legacy integrations
    • Google Consent Mode
    • Google Tag Manager
      • Block cookies with GTM
      • Install Openli with GTM
      • Prevent triggers from firing in GTM
    • HubSpot
    • Pardot
    • Shopify
      • Install cookie widget
      • Integrate consent with checkout
    • Square Online
    • Squarespace
    • Webflow
    • Wix
Powered by GitBook
On this page
  • How to embed a cookie policy
  • Find your cookie policy's public-key
  • Add the embed code to your website
  • How to embed other legal agreements
  • Find your agreement's public key
  • Add the embed code to your website
  • Advanced options
  • Insertion mode
  • Link to a specific part of an agreement
  1. Policy and agreement management

Embed your policies and legal agreements

Openli helps you to manage and update your cookie policy. This feature lets you embed your cookie policy on any page of your website.

PreviousChanging an old cookie policy to a new on autopilotNextEmbedding agreements without displaying a widget

Last updated 1 year ago

How to embed a cookie policy

Find your cookie policy's public-key

Add the embed code to your website

The feature requires both a containing element and a JavaScript snippet to work. You can use an existing HTML element on your page as the container, or add a new one where you want to show the cookie policy on your page.

For example, if you add the following HTML to your page where you want the cookie policy to be shown:

<div id="cookie-policy-container"></div>

...and add the following JavaScript, replacing policy-public-key with the public key of your own cookie policy:

<script>
    // NOTE: This must be placed/run AFTER the code snippet for your cookie widget.
    legal.document("#cookie-policy-container", "policy-public-key");
</script>

...then the latest version of your cookie policy will be displayed inside the <div> element.

If you want to show the cookie policy in an element that already exists on your page, you can use a standard CSS selector that matches it, instead of #cookie-policy-container in the example above.

How to embed other legal agreements

Find your agreement's public key

Add the embed code to your website

The feature requires both a containing element and a JavaScript snippet to work. You can use an existing HTML element on your page as the container, or add a new one where you want to show the policy on your page.

For example, if you add the following HTML to your page where you want the policy to be shown:

<div id="policy-container"></div>

...and add the following JavaScript replacing policy-public-key with the public-key of your own policy:

<script>
    // Replace policy-public-key with your policy's public key.
    legal.document("#policy-container", "policy-public-key");
</script>

...then the latest version of your policy will be displayed inside the <div> element.

If you want to show the policy in an element that already exists on your page, you can use a standard CSS selector that matches it, instead of #policy-container in the example above.

Advanced options

Insertion mode

You can use theinsertMode option to change how and where the agreement is placed in relation to the target element:

<script>
    legal.load("<<WIDGET PUBLIC KEY>>"); // Only needed when the page loads no other widget.

    legal.document("#agreement-target", "<<AGREEMENT PUBLIC KEY>>",  {
         insertMode: "after",
    });
</script>

You can change the insertion method to one of the following options:

Insertion mode

Description

replace (Default)

Replaces the specified target element with the widget

after

Inserts the widget after the specified target element

before

Inserts the widget before the specified target element

Link to a specific part of an agreement

It is important that the CSS selector you use only return one element, so the widget can know which element to scroll into view.

Below we have provided an example of targeting a section element in an agreement, using an ID selector to find it.

Scrolling part of an agreement into view using an id attribute

To target part of an agreement using the id of an element, you can pass the id as the value of the elementIdToFocus option. For example, if your agreement contains a section like this:

<section id="refund-policy">
    <heading>Our refund policy</heading>
    <p>...policy details...</p>
</section>

...then you can make legal.document() ask the browser to scroll that part into view once the agreement has loaded, using this JavaScript:

<script>
    legal.load("<<WIDGET PUBLIC KEY>>");

    legal.document("#agreement-target", "<<AGREEMENT PUBLIC KEY>>",  {
         insertMode: "append",
         elementIdToFocus: "refund-policy",
    });
</script>

If you have a page at https://mysite.example/terms that uses legal.document(), and the agreement you display there has a section with an id of refund-policy like in the example above, you can link to that page, and that section, from anywhere by using a link like this:

and code similar to this:

<script>
    legal.load("<<WIDGET PUBLIC KEY>>");

    // Remove the leading "#" from the returned value, to get only the ID.
    var targetId = window.location.hash.replace(/#/, "")

    legal.document("#agreement-target", "<<AGREEMENT PUBLIC KEY>>",  {
         insertMode: "append",
         elementIdToFocus: targetId,
    });
</script>

This solution is generic, so you can also link to other sections in the same agreement, for example https://mysite.example/terms#cancellation if you have an element with an id of cancellation.

If your agreement does not have any elements with id attributes, you can also use the advanced HTML-editing mode in our WYSIWYG editor to add some. Look for this button in the editor toolbar to edit the HTML code directly:

In your , click "Agreements", and copy the public-key of your cookie policy, as shown in the image below:

In your , click "Agreements", and copy the public-key of your agreement, as shown in the image below for the example of a cookie policy:

You link to a specific part of an agreement using any , and legal.js will scroll it into view.

A simple way to allow dynamic direct linking from other locations is to use the browser's built-in support for (everything after the # in the URL), and pass that to legal.document().

(note the #refund-policy part)

Openli dashboard
Openli dashboard
valid CSS selector
fragment identifiers
https://mysite.example/terms#refund-policy