Make Shopify, its apps, and its pixels follow your cookie banner
TermsFeed Privacy Consent (CMP) does not write to the Shopify Customer Privacy API by itself, so you add a theme block that sends each answer to it. The Customer Privacy API is the Shopify interface that stores consent for the store. Shopify analytics, apps that read the API, and customer events pixels follow the consent held there, not the answer Privacy Consent keeps in localStorage.
Setup takes 3 steps and about 15 minutes in layout/theme.liquid: load the API, send the answer, and restore it for returning visitors. You need access to the theme code, the Privacy Consent snippet in the theme, and the Shopify consent banner turned off. Install the snippet first with Install TermsFeed Privacy Consent on Shopify.
How Shopify consent categories map to Privacy Consent
Shopify has 3 consent categories plus sale_of_data, and Privacy Consent has 5 vendor categories, so your code combines them. analytics follows Analytics and preferences follows Functionality, while marketing and sale_of_data turn true only when the visitor accepts both Advertising and Marketing. Look up every value in the category mapping.
Shopify treats a sale of data opt-out as separate from consent, and its API documentation advises caution when combining them. The code in Step 1 sends false for a visitor who declines, which records that opt-out in Shopify too.
Turn off the Shopify consent banner
Turn off the Shopify consent banner first, because it writes to the Customer Privacy API by itself and a choice it saves replaces the one Privacy Consent sends. Shopify still needs to know which regions require consent, so keep those regions set. The Shopify privacy settings guide describes the same setup for a third-party consent tool.
- In the Shopify admin, open Settings, then Customer privacy, then click "Cookie banner".
- Click the menu, then "Remove cookie banner", then "Remove", where that option appears.
- Click "Set custom banner regions" in the menu, or "Edit" in the Regions section.
- Select every region where your Privacy Consent banner appears, then click "Save".
- Open your storefront in a new private window. Only the Privacy Consent banner appears.
Step 1: Load the Customer Privacy API
Open Online Store, then Themes, then Edit code, then layout/theme.liquid. Paste this block inside <head>, after the line that prints content_for_header and before the Privacy Consent snippet. The API is available at window.Shopify.customerPrivacy only after Shopify loads the consent-tracking-api feature, and tfSendToShopify loads it before each call.
<script>
function tfShopifyConsent(categories) {
var has = function (id) { return categories.indexOf(id) !== -1; };
var ads = has('advertising') && has('marketing');
return {
analytics: has('analytics'),
preferences: has('functionality'),
marketing: ads,
sale_of_data: ads
};
}
function tfSendToShopify(categories) {
if (!window.Shopify || !window.Shopify.loadFeatures) { return; }
window.Shopify.loadFeatures(
[{ name: 'consent-tracking-api', version: '0.2' }],
function (error) {
if (error) { return; }
window.Shopify.customerPrivacy.setTrackingConsent(tfShopifyConsent(categories), function () {});
}
);
}
</script>
Step 2: Send the answer from the Privacy Consent callbacks
Paste this block after the first one. acceptedAll and acceptedSome receive the vendor categories the visitor accepted in full, and rejectedAll receives nothing, so a partly accepted vendor category sends false.
<script>
var callbacks = {
acceptedAll: function (categories) { tfSendToShopify(categories); },
acceptedSome: function (categories) { tfSendToShopify(categories); },
rejectedAll: function () { tfSendToShopify([]); }
};
if (window.termsfeed_privacy_consent !== undefined)
window.termsfeed_privacy_consent.v1.callbacks(callbacks);
else
window.termsfeed_privacy_consent_callbacks = callbacks;
</script>
Each v1.callbacks() call replaces all 4 callbacks, so put the Shopify call in the same functions as any other integration. Merge them with the callback rules.
Step 3: Restore the answer for returning visitors
No answer callback runs on page load for a returning visitor, so this block sends the stored answer to Shopify on every page load. It reads the termsfeed_privacy_consent_state key, counts a vendor category as accepted only when every vendor in it is on, and ignores an answer older than 365 days (12 months). It waits for the page to finish parsing, so window.Shopify exists.
Paste it after the second block. Repeat all 3 blocks in layout/password.liquid where your store shows a password page.
<script>
function tfStoredCategories() {
try {
var record = JSON.parse(localStorage.getItem('termsfeed_privacy_consent_state') || '{}');
var state = record.consentState;
if (!state || !state.consentedDate) { return null; }
if (Date.now() / 1000 - state.consentedDate > 365 * 24 * 60 * 60) { return null; }
return state.categories.filter(function (c) {
return c.vendors && c.vendors.length
? c.vendors.every(function (v) { return v.enabled; })
: c.enabled === true;
}).map(function (c) { return c.id; });
} catch (e) {
return null;
}
}
(function () {
function restore() {
var stored = tfStoredCategories();
if (stored) { tfSendToShopify(stored); }
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', restore);
} else {
restore();
}
})();
</script>
How to verify that Shopify receives the Privacy Consent answer
Read the consent Shopify holds in the Console tab after each answer. These checks need a visit on the opt-in model, where the consent banner appears. The currentVisitorConsent() method returns yes, no, or an empty string for each key.
- Save the theme, open your storefront in a new private window, open DevTools, select the Network tab, and type
events.pushin the filter box. - Click I Agree. A new
events.pushrequest appears, which shows that Privacy Consent recorded the answer. - Select the Console tab and run
Shopify.customerPrivacy.currentVisitorConsent(). Theanalytics,marketing,preferences, andsale_of_datakeys readyes. - Load a second page and run the same command. The keys still read
yes. - Close every private window, open a new one, load the storefront, click I Decline, and run the command again. The keys read
no.
A yes after I Decline means the Shopify consent banner or another app still writes to the API.
Privacy Consent does not run on Shopify checkout
Privacy Consent does not load on Shopify checkout pages, because Shopify does not run theme code there. Shopify applies the consent it holds through the Customer Privacy API, so the storefront has to send the answer before the visitor reaches checkout. The restore block in Step 3 does that on every page.
A choice a visitor changes on checkout itself does not reach Privacy Consent, and no vendor tag runs there. Review the other places the script does not load in the unsupported environments.
Common mistakes with the Shopify Customer Privacy API and Privacy Consent
A Shopify consent banner left on overrides the answer from Privacy Consent. Shopify then writes its own defaults or the choice from its consent banner to the API, and currentVisitorConsent() reads yes after I Decline. Remove it with the steps under Turn off the Shopify consent banner.
Tracking code left in the theme ignores the answer too. A Google Analytics or Meta Pixel snippet pasted in theme.liquid does not read the Customer Privacy API and runs for every visitor. Move each snippet into its own vendor with the vendor recipes.