How the Shopify Customer Privacy API Works

The Shopify Customer Privacy API helps merchants comply with privacy regulations like GDPR and CCPA by allowing apps and third-party services (such as Meta Pixel, Google Ads, and other tracking scripts) to respect user consent—especially on sensitive pages like checkout.

With this API, your JavaScript code can check a visitor’s consent status before loading tracking or marketing tags.

Use the following code to load the API and access the visitor’s consent preferences:

window.Shopify.loadFeatures(
  [
    {
      name: 'consent-tracking-api',
      version: '0.1',
    },
  ],
  (error) => {
    if (error) {
      // Handle loading error
      return;
    }

    // API is ready—check visitor consent
    const consent = window.Shopify.customerPrivacy.currentVisitorConsent();
    console.log(consent);
  }
);

Make sure to place your logic inside the callback, as the API is only available once it's fully loaded.

Example Output

{
  "marketing": "yes",
  "analytics": "yes",
  "preferences": "yes",
  "sale_of_data": "no"
}

The API returns consent status for the following categories:

  • analytics
  • marketing
  • preferences
  • sale_of_data

Each category will return 'yes' or 'no', allowing you to conditionally load or block third-party scripts based on user preferences.