Using Segment Consent Management with Shopify

Updated on 2024-06-26

Segment Consent Management 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.

Littledata uses Shopify's Customer Privacy API to track customer consent. Most Shopify cookie banners 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.

tip:

If your store uses another CMP, your CMP will need to update the customer privacy API with the given consent. We have plugins for OneTrust and TrustArc.

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

Segment Consent TypeShopify Consent Type
Advertisingmarketing
DataSharingsale_of_data
Functionalpreferences
Analyticsanalytics

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

Segment Consent valueShopify Consent value
trueyes
falseno

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

You must configure the Segment destinations 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.

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);
    }
});