Consent Mode v2 Shopify: Setup, Code, and Compliance

Set up Consent Mode v2 on your Shopify store. Learn the four signals, the code snippet, and how to verify it works for Google Ads and GA4.

Eptekhar Hasan9 min read
Illustration for Consent Mode v2 Shopify: Setup, Code, and Compliance

Consent Mode v2 on Shopify requires you to send four specific signals to Google: ad_storage, analytics_storage, ad_user_data, and ad_personalization. You must set a default state before any Google tags load, then update that state when the visitor clicks accept or decline on your cookie banner. If you skip this, Google will not model conversions for users in the EEA, and your remarketing audiences will shrink. This guide shows you exactly where to put the code and how to verify it is working.

Shopify provides a native Customer Privacy API that handles consent for its own managed pixels and checkout. However, it does not automatically handle third-party scripts like Google Analytics 4 or Google Ads unless you bridge that gap. The bridge is the gtag function. When a visitor lands on your store, the browser needs to know immediately whether it is allowed to store cookies or send data to Google. If you do not tell it, the tag might fire before the user has made a choice, which is a compliance violation. If you do tell it, but you do not update it when the user clicks a button, you lose data. The system works in two phases. First, you declare a default. Second, you listen for the user's action and update the state. This logic must run before the actual Google tag initializes.

Google requires four distinct signals for Consent Mode v2. Many guides mention only two, which is the old v1 standard. The two new signals added in v2 are ad_user_data and ad_personalization.

  1. ad_storage: Controls whether Google can store cookies for advertising purposes.
  2. analytics_storage: Controls whether Google can store cookies for analytics purposes.
  3. ad_user_data: Controls whether Google can use personal data (like email addresses) for advertising. This is critical for server-side conversions and customer match lists.
  4. ad_personalization: Controls whether Google can use personal data to personalize ads. This affects dynamic remarketing and audience segmentation.

If you only set the first two, you are running v1. Your store may pass basic checks, but you will miss out on the behavioral modeling that Google uses to fill in the gaps when cookies are blocked. For a Shopify store targeting the EEA, UK, or Switzerland, all four signals must be present.

Step 1: Check your current status

Before you change anything, you need to know if Consent Mode v2 is already active. Some Shopify apps, like Pandectes or Consentmo, handle this automatically. If you are using a manual setup or a different CMP, you need to verify the code is present.

Open your browser's developer tools on your Shopify store. Go to the Console tab. Type gtag('consent', 'default', {'ad_storage': 'granted'}) and press Enter. If you get an error, the gtag library is not loaded, or it is loaded after the consent logic runs.

You can also use a free checker to scan your site. Visit the consent mode checker to see if the four signals are being sent correctly. It tells you which signals are missing or set to the wrong default state, so you know exactly what to fix before you touch the code.

If you are using a third-party app that claims to support Consent Mode v2, check its settings. Look for a toggle labeled "Google Consent Mode" or "Respect Customer Privacy Settings." If it is off, turn it on. The app should then inject the necessary code into your theme automatically. If you are not using an app, you will need to add the code manually.

Step 2: Add the code to your theme

If you are handling this manually, you need to add a script to your theme. The best place is in the <head> of theme.liquid. This ensures the code runs on every page, including the cart and checkout pages, although checkout is often locked down by Shopify.

Here is the logic you need. It sets the default state to "denied" for everyone, except users in the US where it is "granted". It then listens for clicks on Shopify's native cookie banner buttons.

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}

  // Determine default state based on country
  const defaultConsentState = '{{ localization.country.iso_code }}' === 'US' ? 'granted' : 'denied';

  gtag('consent', 'default', {
    'ad_storage': defaultConsentState,
    'analytics_storage': defaultConsentState,
    'ad_user_data': defaultConsentState,
    'ad_personalization': defaultConsentState
  });

  // Listen for banner clicks
  (function loadConsentMode() {
    addEventListener("DOMContentLoaded", () => {
      document.body.addEventListener('click', (e) => {
        const acceptButtonId = 'shopify-pc__banner__btn-accept';
        const declineButtonId = 'shopify-pc__banner__btn-decline';
        
        if(![acceptButtonId, declineButtonId].includes(e.target.id)) {
          return;
        }

        const newState = e.target.id === acceptButtonId ? 'granted' : 'denied';
        
        gtag('consent', 'update', {
          'ad_user_data': newState,
          'ad_personalization': newState,
          'ad_storage': newState,
          'analytics_storage': newState
        });
      })
    })
  })();
</script>

Paste this code into theme.liquid inside the <head> tag, right after the opening <head> tag. You should also add it to password.liquid if you use a password page, though that page usually has less traffic.

This code relies on the IDs of Shopify's native banner buttons. If you change your banner theme or use a custom banner app, those IDs might change. If the IDs change, the "update" part of the code will stop working. You will need to inspect the new banner's HTML to find the correct id attributes for the accept and decline buttons and update the code accordingly.

Step 3: Verify the implementation

Adding the code is not enough. You must verify that it is sending the correct signals. Google provides a test tool for this, but you can also check it manually.

  1. Clear your cookies on your Shopify store.
  2. Open the browser's Network tab.
  3. Reload the page.
  4. Look for requests to google-analytics.com or googletagmanager.com.
  5. Click on one of those requests and look for the query parameters or the payload.

You should see consent=ad_storage=denied;analytics_storage=denied;ad_user_data=denied;ad_personalization=denied if you are in the EEA. If you are in the US, you should see granted.

Next, click the "Accept" button on your cookie banner. Reload the page. The signals should now show granted. If they do not, your click listener is not working. Check the console for JavaScript errors. A common mistake is placing the script after the Google tag. The gtag('consent', 'default') call must happen before the Google tag initializes. If the tag loads first, it will ignore the default state.

Common mistakes and how to fix them

1. The script loads too late. If you put the code at the bottom of your page, the Google tag may have already fired. Move the code to the very top of the <head> section.

2. Hard-coded country logic. The code above uses {{ localization.country.iso_code }}. This is a Shopify Liquid variable. If you replace it with a hard-coded check like navigator.language, it will not work for users who have their browser language set differently from their location. Always use the Shopify variable if you are inside a Liquid template.

3. Ignoring server-side tracking. Consent Mode v2 is a browser-side solution. It tells the browser what to do. If you are using server-side tracking, such as a proxy or a server container, the browser signals do not apply directly to the server request. You must pass the consent state to your server separately. If you are sending purchase events from a server, ensure your server code checks the consent state before sending the event to Google. If the user denied ad_user_data, the server should not send personal data.

4. Using a CMP that does not support v2. Some older cookie banner apps only send ad_storage and analytics_storage. If you are using an app, check its documentation. If it does not mention ad_user_data or ad_personalization, it is not fully compliant with v2. You may need to switch apps or add custom code to bridge the gap.

5. Not updating on preference change. The code above listens for the initial click. If a user changes their mind and clicks "Change Preferences" to toggle a setting, the code must update the consent state again. Shopify's native banner allows users to change their preferences. Your click listener should handle those buttons as well. If you only listen for the main accept/decline buttons, you will miss preference changes.

Does this cover Meta and TikTok?

No. Consent Mode v2 is specific to Google. It tells Google how to handle data. It does not tell Meta, TikTok, or Pinterest how to handle data. If you run ads on those platforms, you need to implement their specific consent frameworks.

For Meta, you need to use the Meta Pixel's consent mode or their Conversions API to handle consent. For TikTok, you need to use their Pixel settings. Getting Google consent right does not automatically protect you on other platforms. You need separate logic for each ad network.

If you are only using Google Ads and GA4, the setup above is sufficient. If you are using multiple platforms, you need a more complex setup. A dedicated Consent Management Platform (CMP) that supports multiple vendors is often easier to manage than writing custom code for each one.

When to use a server-side setup

Browser-based tracking is fragile. Users can block scripts, use ad blockers, or have slow connections. Server-side tracking solves this by sending data from your server directly to Google.

However, server-side tracking does not replace Consent Mode v2. It complements it. You still need to know if the user consented. You can pass the consent state to your server via the dataLayer or a cookie, and then your server checks it before sending the event to Google.

If you are struggling with browser tracking, or if you are losing data due to ad blockers, consider moving to a server-side setup. This is more complex to set up but more reliable. It also allows you to handle consent more robustly, as you can log the consent state on your server for audit purposes.

For a deeper look at how to move your tracking away from the browser, check out our guide on server-side tracking. It covers the architecture and the benefits of moving your data pipeline to the server.

Final checklist

Before you consider this done, run through this list:

  • Code is in theme.liquid in the <head>.
  • Default state is set to "denied" for EEA/UK/CH.
  • Default state is set to "granted" for US.
  • All four signals are present: ad_storage, analytics_storage, ad_user_data, ad_personalization.
  • Click listener updates the state when the user clicks Accept or Decline.
  • Click listener handles preference changes if the banner supports them.
  • You have verified the signals in the Network tab.
  • You have checked if you need separate consent logic for Meta or TikTok.

If you pass all these checks, your Shopify store is compliant with Google Consent Mode v2. You are protecting your data, respecting user choices, and keeping your remarketing audiences intact.

If you are not sure if your setup is correct, or if you want to move to a more robust server-side solution, you can send the details through the contact page for a review. I look at your current tracking and tell you in writing exactly where the gaps are.

Keep reading

All guides