Shopify Theme App Extension
clients/shopify-extension provides an Online Store 2.0 App Embed block that loads Consent Banner v2 and maps grant, partial update, and withdrawal choices directly onto window.Shopify.customerPrivacy.setTrackingConsent.
Enable the App Embed block
- Deploy the extension from clients/shopify-extension using Shopify CLI.
- Open Online Store > Themes > Customize > App embeds in your Shopify Admin.
- Toggle on PolicyGrain DPDP Banner and paste your Site Key. Banner position, theme and copy come from the config you publish in PolicyGrain, not from the theme editor.
- Save your theme. The embed loads https://cdn.policygrain.com/b/v1/loader.js in <head>, and with Sync with Shopify Customer Privacy API on, choices sync analytics, marketing, preferences and sale_of_data to Shopify.
Customer Privacy API mapping
ts
// Handled by assets/policygrain-shopify-bridge.js on every policygrain:choice event.
// PolicyGrain choices are booleans keyed by purpose id.
document.addEventListener("policygrain:choice", (event) => {
const choices = event.detail?.choices ?? {};
const gpc = navigator.globalPrivacyControl === true; // "Honor GPC" setting, on by default
const marketing =
choices.marketing === true || choices.advertising === true || choices.ads === true;
window.Shopify?.customerPrivacy?.setTrackingConsent(
{
analytics: choices.analytics === true,
marketing: gpc ? false : marketing,
preferences: choices.preferences === true || choices.functional === true,
sale_of_data: gpc ? false : marketing || choices.sale_of_data === true,
},
() => {},
);
});