CookieAskInstall guides

Install CookieAsk on Shopify

Templates and presets are not legal advice.

Shopify has its own consent store, the Customer Privacy API. Shopify's apps, its analytics and its customer events read the visitor's choice from it. Two steps are needed: put the CookieAsk loader in your theme, and pass each CookieAsk decision on to Shopify.

1. Switch off Shopify's own banner

Two banners confuse visitors and write two different records. In the Shopify admin open Settings → Customer privacy and turn off Shopify's cookie banner. (The settings page may be named slightly differently in your admin. Keep the Customer Privacy API itself: step 3 uses it.)

2. Add the loader to your theme

  1. In the Shopify admin open Online Store → Themes, and on your live theme choose ⋯ → Edit code. Work on a duplicate first if you like.
  2. Open layout/theme.liquid.
  3. Paste your snippet from the CookieAsk install page directly after the opening <head> tag, above {{ content_for_header }} and above every other script. It is shown here with placeholders; use the one from your dashboard:
<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">
  ...
  {{ content_for_header }}
  1. Save, and publish the banner in CookieAsk if you have not done so.

If your theme has more than one layout (for example layout/password.liquid), add the snippet there too.

3. Pass each decision to Shopify's Customer Privacy API

Shopify expects four values: analytics, marketing, preferences and sale_of_data. Add this block in layout/theme.liquid after the CookieAsk snippet, for example just before </head>. It loads Shopify's consent feature, then sets Shopify's state now and after every later decision, including a withdrawal:

<script>
(function () {
  function toShopify(consent) {
    var c = consent.categories || {};
    return {
      analytics: !!c.analytics,
      marketing: !!c.marketing,
      preferences: !!(c.functional || c.preferences),
      sale_of_data: !!c.marketing
    };
  }
  function start() {
    if (!window.__cmp || !window.Shopify || !window.Shopify.loadFeatures) return;
    window.Shopify.loadFeatures([{ name: 'consent-tracking-api', version: '0.1' }], function (error) {
      if (error) return;
      function push(consent) {
        if (!consent.decided) return;
        window.Shopify.customerPrivacy.setTrackingConsent(toShopify(consent), function () {});
      }
      push(window.__cmp.getConsent());
      window.__cmp.onChange(push);
    });
  }
  start();
})();
</script>

Notes:

4. Check it

Limits on Shopify