> ## Documentation Index
> Fetch the complete documentation index at: https://weaverse.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Weaverse component configuration uses `settings`. `inspector` is deprecated; never generate it.
> Weaverse Hydrogen themes use React Router v7: import from `react-router`, never `react-router-dom` or `@remix-run/*`.
> Before using any code sample, read `@weaverse/hydrogen` in the project's `package.json`: 6.x and 5.x import from different entries and use different type names, so code for one does not build on the other.
> `@weaverse/hydrogen` 6 (Shopify Hydrogen 2026.10 and later, the version these docs show) imports from `@weaverse/hydrogen/react-router` and uses `Weaverse*` types such as `WeaverseComponentProps`, `WeaverseComponentLoaderArgs` and `WeaverseComponentSchema`; the root `@weaverse/hydrogen` entry only exports `createSchema()`, data helpers and types.
> `@weaverse/hydrogen` 5.x (Hydrogen 2026.4 and earlier) imports everything from `@weaverse/hydrogen` and uses `HydrogenComponentProps`, `ComponentLoaderArgs` and `HydrogenComponentSchema`. On a 5.x project, convert samples to these names. Upgrade to 6 only when asked (`npx @weaverse/cli@latest migrate v6`, plus the Hydrogen 2026.10 upgrade). Do not mix major versions.
> Next.js themes use `@weaverse/hydrogen` 6.2.0 or later: import client and shared code from `@weaverse/hydrogen/next` and server-only code from `@weaverse/hydrogen/next/server`. `@weaverse/next` is deprecated; never install or import it.
> For live project data (pages, theme settings, translations), use the Weaverse MCP server: https://weaverse.io/docs/developer-tools/weaverse-mcp

# Cookie Consent Banner

> How to properly configure Shopify's cookie consent banner in Weaverse Hydrogen storefronts, including setup, troubleshooting, and GDPR/privacy compliance.

# Cookie Consent Banner

Shopify provides a built-in **cookie consent banner** that helps your store comply with privacy regulations like GDPR, CCPA, and ePrivacy. In Hydrogen storefronts, this banner requires specific configuration to work correctly because the standard Liquid-based initialization is not available.

This guide walks you through the complete setup, common pitfalls, and how to verify the banner is working.

## How It Works

Shopify's cookie consent system consists of two parts:

1. **Customer Privacy API** (`consent-tracking-api.js`) — Manages visitor consent state and cookies
2. **Privacy Banner** (`storefront-banner.js`) — The visible UI that collects consent from visitors

In a Hydrogen 2026.10 storefront, these scripts are loaded by the `<ShopifyScripts>` component from `@shopify/hydrogen/react`, which replaces classic Hydrogen's `<Analytics.Provider>`. The banner's appearance and behavior (text, regions, position) are configured in **Shopify Admin** under **Settings → Customer privacy**.

> [!NOTE]
>
> The banner configuration (text, regions, theme) is managed entirely in Shopify Admin — not in your Hydrogen code. Your code only needs to pass the correct credentials.

## Setup

### Step 1: Configure the Consent Object in Your Root Loader

In your root loader's critical data function (typically `app/.server/root.ts`), return the consent mode, the public Storefront API token, and the `shop` and `i18n` props for `ShopifyScripts`. Keep them per market, never per shopper, so the document stays cacheable:

```typescript theme={null}
export async function loadCriticalData({ context }: LoaderFunctionArgs) {
  const { storefront, env } = context;
  const storefrontId = env.PUBLIC_STOREFRONT_ID || "";

  return {
    // ... other data
    shopifyScripts: {
      shop: {
        shopId: env.SHOP_ID, // or the Shop GID from a Storefront API query
        storefrontId,
        myshopifyDomain: env.PUBLIC_STORE_DOMAIN,
      },
      // Localizes the banner based on the visitor's market
      i18n: {
        country: storefront.i18n.country,
        language: storefront.i18n.language,
        pathPrefix: storefront.i18n.pathPrefix,
        currency: storefront.i18n.currency,
      },
      channel: storefrontId ? "hydrogen" : "headless",
      shopifyAnalytics: storefrontId !== "",
    },
    consent: {
      // Shopify's hosted privacy banner (classic `withPrivacyBanner: true`)
      mode: "default-banner",
      storefrontAccessToken: env.PUBLIC_STOREFRONT_API_TOKEN,
    },
  };
}
```

`storefront.i18n.currency` is set by your Storefront client's request context; see Pilot's [`app/.server/root.ts`](https://github.com/Weaverse/pilot/blob/main/app/.server/root.ts) for the full version.

> [!WARNING]
>
> The `storefrontAccessToken` must be your **public** Storefront API token (32 characters). Never use a private/admin API token (starts with `shpat_`).

### Step 2: Render ShopifyScripts With the Consent Mode

In your root layout (`app/root.tsx`), render `<ShopifyScripts>` first in `<head>` and pass the consent mode:

```tsx theme={null}
import { ShopifyScripts } from "@shopify/hydrogen/react";
import { useNavigate, useRouteLoaderData } from "react-router";
import { useNonce } from "~/utils/csp";
import { routeTemplates } from "~/utils/route-templates";

export function Layout({ children }: { children: React.ReactNode }) {
  const nonce = useNonce();
  const navigate = useNavigate();
  const data = useRouteLoaderData<RootLoader>("root");

  return (
    <html>
      <head>
        {/* Step 3 */}
        {data ? (
          <ShopifyScripts
            nonce={nonce}
            shop={data.shopifyScripts.shop}
            i18n={data.shopifyScripts.i18n}
            analytics={{ channel: data.shopifyScripts.channel }}
            shopifyAnalytics={data.shopifyScripts.shopifyAnalytics}
            consent={{ mode: data.consent.mode }}
            routes={routeTemplates}
            navigate={navigate}
          />
        ) : null}
      </head>
      <body>{children}</body>
    </html>
  );
}
```

`useNonce` comes from your theme's CSP helpers (see [Content Security Policy](https://weaverse.io/docs/features/content-security.md)), and `routeTemplates` from `createShopifyRouteTemplates()`; see Step 10 of the [v6 migration guide](https://weaverse.io/docs/migration-advanced/v6-migration.md).

### Step 3: Expose the Storefront Access Token to the Banner

This is the **critical step** that most setups miss. The banner script (`storefront-banner.js`) loads and self-initializes before React hydrates, and needs your public Storefront API token to authenticate with the Storefront API.

**Render the token in a `#shopify-features` JSON script in `<head>`**, before `<ShopifyScripts>`, so it's available before the banner script executes:

```tsx theme={null}
<head>
  {/* storefront-banner.js reads the public token from this tag */}
  <script
    id="shopify-features"
    type="application/json"
    suppressHydrationWarning
    dangerouslySetInnerHTML={{
      __html: JSON.stringify({
        accessToken: data?.consent?.storefrontAccessToken ?? "",
      }),
    }}
  />
  {/* <ShopifyScripts ... /> from Step 2 */}
</head>
```

> [!TIP]
>
> The `suppressHydrationWarning` attribute is needed because this script's output can differ between server and client renders, which is expected and harmless.

### Step 4: Configure the Banner in Shopify Admin

1. Go to **Shopify Admin → Settings → Customer privacy**
2. Under **Cookie banner**, click **Set up** or **Edit**
3. Configure:
   * **Banner position** — Bottom center, bottom left, etc.
   * **Banner text** — Customize the consent message
   * **Button labels** — Accept, Decline, Manage preferences
   * **Region visibility** — Select which countries see the banner
   * **Theme** — Light or dark, custom colors
4. Click **Save**

### Step 5: Set Up Environment Variables

Ensure these variables are set in your `.env` file and deployment environment:

```bash theme={null}
PUBLIC_STORE_DOMAIN=your-store.myshopify.com
PUBLIC_STOREFRONT_API_TOKEN=your-32-character-public-token
PUBLIC_CHECKOUT_DOMAIN=checkout.your-domain.com
```

> [!NOTE]
>
> The `PUBLIC_CHECKOUT_DOMAIN` should be your custom checkout domain (e.g., `checkout.yourdomain.com`). If you don't have a custom domain, use your `.myshopify.com` domain.

## Verifying the Banner Works

### Preview Mode

Add `?preview_privacy_banner=1` to any page URL to force the banner to display regardless of region or prior consent:

```
https://your-store.com/?preview_privacy_banner=1
```

This is useful for testing during development. Without this parameter, the banner only appears for visitors in configured regions who haven't yet given consent.

### Checklist

Use this checklist to verify your setup:

* `consent.mode` is `"default-banner"` in the root loader and reaches `<ShopifyScripts consent={{ mode }}>`
* `storefrontAccessToken` is a valid 32-character public token
* The `#shopify-features` script with the token is rendered in `<head>` before `<ShopifyScripts>`
* Banner appears with `?preview_privacy_banner=1`
* Banner appears for visitors in configured regions (without preview param)
* Accepting/declining sets the `_tracking_consent` cookie
* `window.Shopify.customerPrivacy` is not null after page load

### Browser Console Check

Open DevTools and verify the privacy API initialized:

```javascript theme={null}
// Should return an object with consent methods
window.Shopify.customerPrivacy

// Should return a boolean
window.Shopify.customerPrivacy.shouldShowBanner()

// Should return the current consent state
window.Shopify.customerPrivacy.currentVisitorConsent()
```

## Troubleshooting

### "Error initializing banner: Missing access token"

**Cause:** The banner script loaded without finding the public Storefront API token.

**Fix:** Add the `#shopify-features` script in Step 3 to `<head>`, before `<ShopifyScripts>`.

### "Could not find liquid access token"

**Cause:** This is a harmless warning. The banner script first checks for a Liquid-based token (used in traditional Shopify themes). In Hydrogen, this path doesn't exist, so the script falls back to the Storefront API path.

**Resolution:** This warning can be safely ignored as long as the Storefront API token is correctly configured.

### Banner Shows in Preview Mode but Not in Production

**Cause:** The banner's `init()` function failed silently because it couldn't find the access token during initial load. With `?preview_privacy_banner=1`, the script forces initialization and bypasses this check.

**Fix:** Ensure Step 3 is implemented — the `#shopify-features` script must carry the token in the server-rendered HTML, before React hydrates.

### `window.Shopify.customerPrivacy` is null

**Cause:** The banner script failed to initialize, which means it never set up the Customer Privacy API. This prevents the banner from showing and analytics consent from working.

**Fix:** This is almost always caused by the missing access token (follow Step 3), or by a CSP nonce that doesn't reach `<ShopifyScripts>`. Check the console for CSP violations.

### Banner Doesn't Show for Specific Regions

**Cause:** The region visibility configuration in Shopify Admin may not include the visitor's country.

**Fix:** Go to **Shopify Admin → Settings → Customer privacy → Cookie banner** and verify the region visibility list includes the target countries.

### React Hydration Error (#418) Alongside Banner Errors

**Cause:** A hydration mismatch between server-rendered HTML and client-rendered output. This is separate from the banner issue but often appears together.

**Resolution:** Use `suppressHydrationWarning` on the inline script tag (as shown in Step 3). For other hydration errors, check that your components render the same content on server and client.

## How the Banner Initialization Flow Works

Understanding the initialization sequence helps with debugging:

```
1. Server renders HTML with:
   <script id="shopify-features">{"accessToken":"abc123..."}</script>
   <ShopifyScripts consent={{ mode: "default-banner" }} ... />

2. Browser loads storefront-banner.js (from Shopify CDN)
   → Finds the public access token ✓
   → Calls Storefront API to get consent cookies
   → Calls Storefront API to get banner configuration
   → Sets window.Shopify.customerPrivacy
   → Sets window.privacyBanner

3. ShopifyScripts loads the banner for the market in its i18n prop
   → Banner renders with correct localization
   → The analytics bus (window.Shopify.analytics) follows consent

4. Visitor interacts with banner
   → Consent collected → _tracking_consent cookie set
   → Analytics events fire based on consent
```

## Further Reading

* [Shopify Customer Privacy API](https://shopify.dev/docs/api/customer-privacy)
* [Shopify Hydrogen Analytics](https://shopify.dev/docs/storefronts/headless/hydrogen/analytics)
* [Content Security Policy in Weaverse](https://weaverse.io/docs/features/content-security.md)
* [Third-party Integrations](https://weaverse.io/docs/features/third-party-integrations.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.