How Captain Compliance Syncs Consent with the Shopify Customer Privacy API
Shopify’s Customer Privacy API is how a Shopify store learns what a visitor has agreed to. Shopify uses it for its own tracking, and apps and pixels read it to decide what they may do. When the Captain Compliance banner runs on a Shopify storefront, it updates this API for you. This article explains what Captain Compliance sends, when it sends it, and how to check it.
There is nothing to configure. The update is part of the banner script, so it works as soon as the script is on the storefront. To add the script, see How to Install the Captain Compliance Consent Banner on Shopify.
Before you start
Install the Captain Compliance script in the theme. The update only happens on pages where the script runs.
Turn off Shopify’s own cookie banner, under Settings → Customer privacy in the Shopify admin. Shopify’s banner writes to the same API, so two banners can overwrite each other. See How to Integrate Captain Compliance with Shopify.
How the update works
The banner script checks whether the page is a Shopify storefront.
If the theme has not already loaded Shopify’s consent tracking feature, the script asks Shopify to load it, and waits up to 10 seconds for it.
The script converts the visitor’s Captain Compliance categories into Shopify’s four consent values.
The script sends the values to Shopify with Shopify’s
setTrackingConsentmethod.
How categories map to Shopify’s values
Shopify value | Captain Compliance category | Notes |
|---|---|---|
| Performance | |
| Targeting | Sent as no when the visitor has turned on Do Not Sell or Share My Personal Information |
| Functionality | |
| Targeting | Sent as no when the visitor has turned on Do Not Sell or Share My Personal Information |
Strictly Necessary has no Shopify value, because it is always on. Shopify reports each value as yes, no, or an empty string. An empty string means that Shopify has no decision yet.
When Captain Compliance sends an update
Situation | What is sent |
|---|---|
First page view, before the visitor chooses | The default state of your banner configuration for the visitor’s region. A category that is on by default is sent as yes, and a category that is off by default is sent as no. |
The visitor selects Allow, Reject, or Allow Selection | The visitor’s choice, immediately. |
A later page view, when a choice is stored | The stored choice, again. |
The browser sends a Global Privacy Control (GPC) signal | The choice that your GPC settings produce. Marketing and sale of data are sent as no. |
Because the default follows your regional configuration, a region that you set up as opt-out starts at yes, and a region that you set up as opt-in starts at no. See How to Create Regional Consent Banner Configurations.
Examples
These results come from a test storefront with all categories on by default.
Visitor action |
|
|
|
|
|---|---|---|---|---|
No choice yet | yes | yes | yes | yes |
Reject | no | no | no | no |
Cookie Settings with only Performance on, then Allow Selection | yes | no | no | no |
Browser with GPC turned on | no | no | no | no |
In the standard configuration, a GPC signal turns off every optional category, so all four values are sent as no. In Bucket Mode, the result follows the settings of each bucket. See How to Use Bucket Mode to Customize Consent Categories and GPC Behavior.
Check the values in the browser
Open the storefront in a private or incognito browser window, and wait for the banner.
Open the browser console and run the first command below. It shows what Shopify holds for this visitor.
Make a choice in the banner, and run the command again. The values should match your choice.
To compare, run the second command. It shows the same four values as Captain Compliance calculates them from the stored choice. It returns
nulluntil a choice is stored.
Shopify.customerPrivacy.currentVisitorConsent();
// {marketing: "no", analytics: "yes", preferences: "no", sale_of_data: "no"}
CaptainConsent.getShopifyConsent();
// {marketing: false, analytics: true, preferences: false, sale_of_data: false}For more detail, add ?cc_debug=true to the page address and reload. The banner script then writes its steps to the console. A line that starts with [CC] Synced consent with Shopify: confirms each update.
React to a choice in your own code
Theme code can listen for a change in the visitor’s choice. The callback receives the four values as true or false. Place this code after the Captain Compliance script, so that the CaptainConsent object exists when the code runs.
CaptainConsent.on('consentChanged', function (consent) {
if (consent.analytics) {
// Start analytics that needs consent
}
});Code that should also respect the store’s Shopify privacy settings can use Shopify’s own checks, such as Shopify.customerPrivacy.analyticsProcessingAllowed() and Shopify.customerPrivacy.marketingAllowed(). See Shopify’s Customer Privacy API reference.
Limits
The update runs only where the banner script runs. Checkout pages are not built from the theme, so the script does not run there. Shopify keeps the values that were set on the storefront.
The update depends on the
window.Shopifyobject that standard Shopify themes provide. On a headless storefront, the update runs only if that object is present.Each app decides how to use the values. An app that ignores the Customer Privacy API is not held back by it. For those tools, see How to Integrate Captain Compliance with Shopify.
Shopify also reads GPC on its own in regions where the store is set up for data sale opt-out. That handling cannot be changed through the API.
If the values look wrong
All values are empty strings. The banner script is not running on the page. Confirm that the script is in
theme.liquidand that the page’s address is the domain that you added in Captain Compliance. See How to Troubleshoot a Consent Banner That Does Not Appear or Respond.Shopify.customerPrivacyis undefined. Shopify’s consent tracking feature has not loaded yet. Wait a few seconds after the page loads, and run the command again.The values change back after you choose. Another banner or consent app is writing to the same API. Turn off Shopify’s cookie banner and any other consent app.
An app still runs after Reject. The app may not read the Customer Privacy API. See How to Integrate Captain Compliance with Shopify.
