Add Cookie Compliance to a Shopify store

Cookbook · platform Last verified View raw markdown (for agents)

In short: paste the live snippet as the first thing inside <head> in layout/theme.liquid, via Online Store → Themes → theme actions (⋯) → Edit code — not the checkout "Additional scripts" field, and not a Custom Pixel added through Settings → Customer events.

You need #

The wrong way #

The right way #

  1. Get the live snippet (MCP install.getSnippet or dashboard Integrations → Manual Integration).
  2. Online Store → Themes → find the live theme → theme actions menu (⋯) → Edit code.
  3. Open layout/theme.liquid.
  4. Paste the snippet as the very first thing after the <head> tag — before the <meta charset> line, before every {%- if ... -%} block, and before {{ content_for_header }}.
  5. Save.
<!doctype html>
<html class="no-js" lang="{{ request.locale.iso_code }}">
  <head>
    <!-- Cookie Compliance FIRST — before anything else in <head> -->
    <script>
        var huOptions = {
        "appID": "YOUR_APP_ID",
        "currentLanguage": "en",
        "blocking": true,
        "globalCookie": false
    };
    </script>
    <script src="https://cdn.hu-manity.co/v2/hu-banner.min.js" type="text/javascript" charset="utf-8"></script>
    <!-- A new app. If the live snippet has no /v2/, the app is on v1 — keep that URL. -->

    <meta charset="utf-8">
    <!-- ...rest of the theme's existing <head>, including {{ content_for_header }}, unchanged... -->

layout/theme.liquid is shared by every template (home, product, collection, cart, page), so one edit covers the whole storefront. It does not cover checkout or the order-status page — those render through Shopify's separate Checkout system, out of scope for a theme edit.

Gotchas #

Check it works #

Run verify-install (skills/verify-install/SKILL.md) against the live storefront. Shopify-specific extra:

# Check Pass
SP1 Fetch the raw HTML response (not the live DOM) for / huOptions and the hu-banner.min.js tag are the first content inside <head>, before <meta charset> and before {{ content_for_header }}'s output.
SP2 Load the storefront in a fresh session The consent banner renders (tiers/choices appear) before any interaction.
SP3 Add a real tracker tag (e.g. <script async src="https://www.googletagmanager.com/gtag/js?id=...">) below the snippet in theme.liquid, reload, inspect the live DOM The tag's src is emptied and moved to data-src, type becomes javascript/blocked, and a hu-blocked class is added — it never executes pre-consent.
SP4 document.head.firstElementChild in the live DOM Will usually be Shopify's own async analytics script, not the Cookie Compliance snippet — expected per the gotcha above, not a failure.

Verified 2026-09-30 against a real Shopify dev store (Partners-created, *.myshopify.com, password-gated, no real customer data), a real non-production Cookie Compliance AppID, and a real googletagmanager.com/gtag/js tag as the test tracker: the tracker rendered with type="javascript/blocked", class hu-blocked, data-hu-category="2", and its src moved to data-src — confirmed via the live DOM, not the tool's own preview response. The test tracker line was removed from theme.liquid after verification; only the real Cookie Compliance snippet remains live on that store.