Cookie consent and Google Consent Mode v2 in Magento 2
How to add a consent banner to a Magento 2 & Hyvä store, send the visitor’s choice to Google tags and check that it works. About 20 minutes if you have shell access to the store.
Before you start
You need:
- Magento Open Source or Adobe Commerce 2.4.6 to 2.4.9, on PHP 8.1 to 8.4.
- A Luma or Hyvä theme, or a theme based on either. The setup is the same on both.
- Admin access and shell access to the Magento root, so you can run
bin/magento. - A wwcookie account. The free plan is enough to follow this guide.
If the store already has another consent tool, or Magento’s own Cookie Restriction Mode, plan to switch it off at the end. Two banners on one page send conflicting signals to Google.
1. Add the store and copy its site key
- Sign in to the wwcookie dashboard and add your store’s domain as a new site.
- Open Installation and choose Magento as the installation method.
- Download the module ZIP and copy the site key shown under it.
Each Magento store view can have its own key, so if you run several domains from one Magento install, add each domain as its own site.
2. Install the module
Upload the ZIP to the Magento root and run:
unzip wwcookie-magento-1.0.0.zip -d .
bin/magento module:enable WWCookie_Consent
bin/magento setup:upgrade
bin/magento cache:flushIn production mode, also run bin/magento setup:di:compile and bin/magento setup:static-content:deploy, as after any module install.
The module adds no RequireJS, jQuery or Alpine code and no theme files, so on Hyvä there is nothing to add to your Tailwind config.
3. Enter the site key in Magento admin
- Go to Stores › Configuration › General › wwcookie.
- Pick the scope: default, website or store view.
- Set Enable to Yes, paste the site key and click Save Config.
- Flush the cache: System › Cache Management, or
bin/magento cache:flush. If you use Varnish or a CDN, clear that too. Cached pages keep their old head until you do.
The module prints the wwcookie script at the start of <head>, before Magento’s own scripts. That order matters: the default consent state has to exist before any Google tag runs.
4. Set Google Consent Mode v2
In the wwcookie dashboard, open Consent Banner and the Consent Mode tab. Consent Mode v2 is already on; here you choose how it behaves.
- Mode. In Basic mode, Google tags wait until the visitor makes a choice. In Advanced mode, they send cookieless signals before consent. Which one suits your store is your decision, ideally with your legal adviser. Advanced mode is on paid plans.
- Regional defaults. Separate defaults for EU/EEA · UK · Switzerland, Türkiye and other countries, based on common legal requirements. You can change any value; every change goes to the activity log.
- Update wait time. How long Google tags wait for the banner before they go ahead with the default state.
The four Google signals follow the visitor’s choice of cookie groups:
ad_storage,ad_user_dataandad_personalizationfollow Marketing.analytics_storagefollows Analytics.
Save your changes and publish the banner. Visitors keep seeing the live version until you publish.
5. Connect your Google and marketing tags
How you load GA4, Google Ads or Meta in Magento decides what you do next:
- Google Tag Manager. Keep your tags in GTM. Google tags read Consent Mode by themselves. For other tags, such as Meta Pixel, add a consent check in the tag’s Consent Settings, or let wwcookie’s automatic blocking hold them.
- Magento’s built-in Google Analytics or Google Ads settings, or an extension that prints gtag. These load after the wwcookie script, so they see the default state and the visitor’s update.
- Scripts pasted into the theme or HTML Head › Scripts and Style Sheets. Automatic blocking holds scripts from known analytics and marketing services. For anything it does not recognise, add
type="text/plain"anddata-wwc-category="marketing"(oranalytics) to the script tag.
If you pasted the wwcookie code into the theme or GTM before installing the module, remove that copy so the script loads from one place only.
Magento settings to check
- Cookie Restriction Mode: turn it off under Stores › Configuration › General › Web › Default Cookie Settings, otherwise visitors see two notices.
- Move JS code to the bottom of the page (Advanced › Developer › JavaScript Settings): keep it off. When it is on, the script still runs first, but it can no longer hold iframes in the page body.
- Content Security Policy: the module adds
https://wwcookie.comtoscript-srcandconnect-src, so the banner also works on checkout. If you set a custom logo in the dashboard, add its host toimg-src. - Full page cache and Varnish: the output depends only on the store view, never on the visitor, so pages stay fully cacheable.
- HTML optimisers: the script tag carries
data-cfasync="false"and the usual “do not defer” attributes. A full-page optimiser that ignores them can still move it; check the head after any change.
6. Check that it works
- Open the store in a private window. The banner should appear.
- In the wwcookie dashboard, open Installation and run the Installation check. Look for “Consent Mode default is set first”. If it says the default was not first, something prints a Google tag above the wwcookie script.
- With Google Tag Assistant or GTM preview, check that the page starts with the consent state denied and changes to granted after you accept.
- Check checkout too: the banner should not block the payment form, and your payment methods should load as before.
Want to try this on your own Magento store first? You can open a demo Magento store, or write to MageBooster: they work on Magento 2 & Hyvä stores and can set it up with you.
wwcookie helps you ask for consent and keep a record of each choice. A consent banner is one part of your privacy work and is not legal advice.
Add the banner to your Magento store
Start on the free plan. Your site key and the Magento module are ready as soon as you add your domain.