Add a cookie compliance banner to your theme
You can add a cookie compliance banner to your theme to allow customers to consent to tracking of non-essential cookies. This allows customers to consent to relevant, region-specific, tracking laws such as GDPR and CCPA.
There are two main aspects to adding this to your theme:
The functionality of the banner in the example below provides customers with the option to "accept" or "decline" cookie tracking, hides the banner once a selection has been made, and saves the selection to prevent the banner from being shown in the future. This selection is saved for 365 days, or until the customer clears their cookies.
Create a snippet to host the bannerAnchor link to section titled "Create a snippet to host the banner"
The banner functionality consists of two main components:
- The banner HTML
Shopify.loadFeaturesAnchor link to section titled "Shopify.loadFeatures"
Shopify.loadFeatures method accepts two parameters:
An array of objects that define which features to load. Accepts two parameters:
A callback function with a single error parameter. The function should include a conditional to actually handle the error.
Include the snippetAnchor link to section titled "Include the snippet"
cookie-banner.liquid snippet created, you need to reference it. As this functionality should be present on all pages, you should include the snippet in your main layout, which is commonly
To preview the cookie banner on your theme, you'll need to limit data collection from the customer privacy section of your online store preferences. Then, you'll need to visit the website from one of your targeted regions for limited data collection. For more information about collecting consent for data collection, refer to the Customer Privacy API.