CookieAskInstall guides

Install CookieAsk on a plain HTML site

Use this for hand-written sites, static site generators (Jekyll, Hugo, Eleventy, Astro) and any server that renders its own <head>.

Templates and presets are not legal advice.

1. Get your snippet

Open your site in the CookieAsk dashboard, then Install the banner. The page shows your snippet with your own loader address and site key filled in. Below, the same snippet is shown with placeholders: replace YOUR-LOADER-ORIGIN and YOUR-SITE-KEY with the values from the dashboard, or copy the snippet from the dashboard instead.

<script src="https://YOUR-LOADER-ORIGIN/l/YOUR-SITE-KEY.js" referrerpolicy="origin"
        data-cfasync="false" data-skip-moving="true" data-no-optimize="1" nowprocket></script>

Leave the attributes as they are. They keep speed plugins and script optimizers from delaying the loader, and a delayed loader cannot block scripts in time.

2. Paste it first in <head>

Put the tag in your shared layout or page template, as the first element inside <head>, before every other script, tag manager and analytics tag. Do not add async or defer: the loader has to run before the page's other scripts.

<!doctype html>
<html lang="en">
<head>
  <script src="https://YOUR-LOADER-ORIGIN/l/YOUR-SITE-KEY.js" referrerpolicy="origin"
          data-cfasync="false" data-skip-moving="true" data-no-optimize="1" nowprocket></script>
  <meta charset="utf-8">
  <title>My site</title>
  <!-- your other scripts and tags come after the loader -->
</head>

3. Publish the banner and deploy

The banner shows on your site only after you publish it in the banner editor. Deploy your site, open it in a private window, and answer the banner. The Installation status card on the install page then shows the last consent event and where it came from.

4. If your site sends a Content-Security-Policy

Add the entries shown under If your site sets a Content-Security-Policy on the install page (a script-src entry for the loader address and a connect-src entry for the event endpoint). If your policy uses nonces, give the snippet the same nonce as your other scripts; the loader passes it on to the scripts it releases.

5. Reading a visitor's choice from your own code

The loader defines window.__cmp before any later script runs:

<script>
  // Runs after the loader, so window.__cmp exists. Optional: it is only needed to react to choices yourself.
  var consent = window.__cmp.getConsent();
  if (consent.decided && consent.categories.analytics) {
    // the visitor allowed analytics
  }
  window.__cmp.onChange(function (next) {
    // called after every decision, including a later withdrawal
  });
</script>

For a "Cookie settings" link in your footer, call window.__cmp.showPreferences() from its click handler.

Check it works