Customer Privacy API
window.Shopify object and is accessible to all Shopify online stores.
You can use the API to build consent collection mechanisms such as banners for General Data Protection Regulation (GDPR) compliance. For marketing and analytics use cases, you can use the API when tracking or exporting data about storefront visitors to cover both GDPR compliance and accordance with the California Consumer Privacy Act (CCPA).
What you'll learn
You can use the following methods for consent collection:
window.Shopify.loadFeatures- Loading pattern that must be used to ensure that the API is available when your banner initializes.
shouldShowGDPRBanner(): boolean- Determines whether to show a GDPR banner on the storefront.
setTrackingConsent(consent: boolean, callback: function)- Sets the visitor’s consent as accepted or declined after they interact with the banner.
If the API fails to load, then the banner won't initialize.
Loading pattern for consent collection
To initialize the Customer Privacy API, you need to use the
loadFeatures method and initialize your banner in the callback function.
You can use this method to determine if you should show a GDPR banner.
This method returns a boolean value that indicates if you should show a GDPR banner to the visitor.
The response aggregates the visitor’s location, the merchant’s preference, and whether the visitor has already provided a consent value in the past year.
|Visitor consent provided in past year||Visitor in EU||Merchant limits tracking for customers in Europe||Boolean value|
|Not applicable||Not applicable||✘||
setTrackingConsent(consent: boolean, callback: function)
You can use this method to set a buyer's response to a tracking consent request.