How to add a cookie compliance banner to your Shopify theme manually

You can add a cookie compliance banner to your theme to allow customers to consent to track of non-essential cookies. This allows customers to consent to relevant, region-specific, tracking laws such as GDPR and CCPA.

Following the below steps to adding this to your Shopify theme:

Step 1: Create a snippet to host the banner

  1. From your Shopify admin, go to Online Store > Themes.
  2. Click Actions, and then click Edit Code.
  3. Under the Snippets folder, click on Add a new snippet link to create a new snippet
  4. Fill the snippet name – cookie-banner to the field on the dialog and click Create snippet button.
  5. In the online code editor, please paste the below code
  6. Click Save.

Step 2: Include the snippet

  1. Under the Layout folder, click onto theme.liquid to open the file editor.
  2. In the online code editor, scroll down the page until you find the close body tag.
  3. Paste the below code just before the tag
  4. Click Save and you are done.

The functionality of the banner in the guide above 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.

Happy coding!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *