Customer Privacy API

The customer privacy API is a browser-based, Javascript API that enables developers to read and write cookies related to a buyer's consent to be tracked. The API is implemented as a property on the global window.Shopify object and is accessible to all Shopify online stores. The API can be used to determine if a buyer has consented to region-specific tracking laws such as GDPR or CCPA.

To activate the Customer Privacy API, you will need to use the loadFeatures method:

   name:   'consent-tracking-api',
   version: '0.1',
}], function(error) {
  if (error) {
    throw error;
  // window.Shopify.customerPrivacy will be available when this callback
  // is called.

getTrackingConsent(): String

You can use this method to determine whether the buyer has explicitly consented to be tracked.

Request data


The request doesn't take any request parameters.


This method returns a string that indicates the buyer's consent status with one of the values defined in the table below:

Value Type Description
"yes" string The buyer has explicitly given tracking consent.
"no" string The buyer has explicitly declined tracking consent.
"no_interaction" string The buyer has neither accepted or declined to be tracked.

You can use this method to set a buyer's response to a tracking consent request.

Request data

window.Shopify.customerPrivacy.setTrackingConsent(consent: boolean, callback: function);

Request parameters:

Name Type Description
consent boolean Indicates the buyer's response to the tracking consent request. You can obtain the response using a banner UI element or other similar mechanism. If set to true, then the API returns a custom event called trackingConsentAccepted. If set to false, then no custom event is returned but the callback function is still executed.
callback function A function that executes after the API has set tracking consent. You can use this function to hide the UI banner element or execute a similar task.

Example request:

The following example request shows a Javascript function that sets consent to true and executes another function to hide the banner. For a complete implementation, see Create a cookie compliance banner for your online store.

function handleAccept(e) {
  window.Shopify.customerPrivacy.setTrackingConsent(true, hideBanner);
  document.addEventListener("trackingConsentAccepted", function () {
    console.log("trackingConsentAccepted event fired");


The API executes the callback function and optionally emits a custom event called trackingConsentAccepted.

Example response:

A successful request returns an empty object:


If there is an error with the request, an error object is returned:


userCanBeTracked(): boolean

You can use this method to return the user's consent status.

Request data



The API returns a boolean value indicating whether or not a user can be tracked.

User consent Merchant allows non-essential cookies Boolean value
Not applicable
If merchant Shopify admin preference is set to Allow non-essential cookies, the result is always true
Not declared false