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
- In the Shopify admin open Online Store → Themes, and on your live theme choose ⋯ → Edit code. Work on a duplicate first if you like.
- Open
layout/theme.liquid. - 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 }}
- 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:
- The category names are the slugs of your CookieAsk categories (
analytics,marketing,functional). If you renamed or added categories, change the mapping. sale_of_datais set frommarketinghere. Shopify uses it for the "do not sell or share" choice of opt-out regions; decide with your own advisers what it should follow.- Until a visitor decides, nothing is sent and Shopify keeps its own default.
4. Check it
- Open your shop in a private window: the CookieAsk banner shows, Shopify's does not.
- Accept, then in the browser console run
window.Shopify.customerPrivacy.currentVisitorConsent(). It should report your choices. - The Installation status card on the CookieAsk install page shows the last consent event.
Limits on Shopify
- Checkout. Shopify does not run theme code on checkout and order status pages, so the banner does not appear there. A visitor's choice made on the storefront is carried by Shopify's own consent state; tags in checkout come from Shopify's Customer events and follow the Customer Privacy API value set in step 3.
- Apps that add tags (pixels, review widgets) may inject scripts the CookieAsk blocker cannot see before it runs. The scanner lists them; give such apps their own consent setting where they have one.
- Speed apps that delay or move scripts: exclude the CookieAsk loader from them.