> For the complete documentation index, see [llms.txt](https://help.littledata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.littledata.io/integrations/shopify-to-segment/segment-consent-management.md).

# Using Segment Consent Management with Shopify

### What is Segment Consent Management?

[Segment Consent Management](https://segment.com/docs/privacy/consent-management/consent-in-segment-connections/) accepts signals from your Consent Management Platform (CMP) to capture and enforce user consent preferences, routing events only to destinations approved by the user.

Segment requires every event from your sources to include end-user consent preferences, captured by your CMP or application logic, in the form of the [consent object](https://segment.com/docs/privacy/consent-management/consent-in-segment-connections/#consent-object).

### How does Littledata work with Segment Consent Management?

Littledata uses Shopify's Customer Privacy API to track customer consent. Most [Shopify cookie banners](/partner-recipes/cookie-consent-integrations/shopify-customer-consent-api.md) and some Consent Management Platforms (CMPs) support this Customer Privacy API.

For **Consent Mode** to work, you must have a cookie banner. You can set it up from your Shopify Admin by going to **Settings** -> **Customer** **Privacy** -> **Cookie** **Banner**.

{% hint style="success" %}
If your store uses another CMP, your CMP will need to update the [customer privacy API](https://shopify.dev/docs/api/customer-privacy) with the given consent, or use a plugin for [OneTrust](/partner-recipes/cookie-consent-integrations/integrating-onetrust-shopify.md).
{% endhint %}

### Mapping of Shopify consent types to Segment

Shopify’s Customer Privacy API supports four consent types, and Littledata maps these onto Segment Consent.

| Segment Consent Type | Shopify Consent Type |
| -------------------- | -------------------- |
| Advertising          | marketing            |
| DataSharing          | sale\_of\_data       |
| Functional           | preferences          |
| Analytics            | analytics            |

For all consent types a `true` value equals a 'yes' value on Shopify.

| Segment Consent value | Shopify Consent value |
| --------------------- | --------------------- |
| `true`                | yes                   |
| `false`               | no                    |

This `consent` object is sent with all events within the event `context` object.

### Configuring Segment destinations to use consent

You must [configure the Segment destinations](https://segment.com/docs/privacy/consent-management/configure-consent-management/) to decide which ones are Advertising, Analytics, Functional or DataSharing.

You can ignore step 2 (integrating your CMP) because Littledata has already done this for the [Shopify source](https://segment.com/docs/connections/sources/catalog/libraries/website/shopify-littledata/).

### Blocking all client-side events based on consent

If you prefer not to collect non-consenting customer data in Segment, then you can exclude client-side events using source middleware for **Segment’s AnalyticsJS library**.

This example middleware script would drop events from being triggered if `context.consent.categoryPreferences.Advertising` is not `true`.

```
window.analytics = window.analytics || [];
// Temporary implementation before the real script loads
if (!window.analytics.addSourceMiddleware) {
  window.analytics.addSourceMiddleware = function () {
   const e = Array.prototype.slice.call(arguments);
   e.unshift('addSourceMiddleware');
   window.analytics.push(e);
   return window.analytics;
  };
}
window.analytics.addSourceMiddleware(({ payload, next }) => {
    if(payload?.obj?.context?.consent?.categoryPreferences?.Advertising) {
        next(payload);
    }
});
```
