Magento 2 cookie consent: a GDPR banner for Magento and Adobe Commerce
Free scan: what loads on your site before consent?
Scan your store's homepage and a product page to see which cookies and trackers load before anyone clicks. No sign-up.
Magento's built-in Cookie Restriction Mode tells visitors cookies are needed and asks them to click Allow — Adobe's description has no way to refuse. This guide replaces it with a banner that offers Accept and Reject, installs it from the admin without code, sets Google Consent Mode v2, and covers the three Magento details that break most setups: the order of scripts in the head, the 'Move JS code to the bottom' setting, and the Content Security Policy that blocks unlisted scripts on checkout since 2.4.7.
Facts checked · Sources
Cookie Restriction Mode vs a consent banner
What Adobe documents for Magento's built-in option, next to what PrivacyPill adds.
| Magento Cookie Restriction Mode | PrivacyPill | |
|---|---|---|
| What visitors see | A message that cookies are required for full-featured operation, a privacy policy link and an Allow button; Adobe doesn't describe a reject option | Accept all and Reject all side by side, plus preferences by category |
| Where it appears | Depends on the theme — above the header, below the footer or elsewhere | Floating pill, bottom bar, modal or corner badge, styled in the customizer |
| What waits for consent | Magento's Google Analytics doesn't collect data until visitors accept, Adobe says; other trackers aren't covered in its description | Any script marked type="text/plain" with data-pp-category; Google tags through Consent Mode v2 |
| Google Consent Mode v2 | Not mentioned in the 2.4.7 or 2.4.8 release notes | Defaults denied in the head, updated on every choice |
| Record of the choice | The user_allowed_save_cookie cookie | Every choice logged pseudonymously with the banner version, exportable as CSV |
| Price | Included in Magento Open Source and Adobe Commerce | Free for one store up to 5,000 pageviews a month; Lifetime €49 once |
Adobe facts checked 16 November 2026 on Experience League and developer.adobe.com — see Sources.
Install PrivacyPill on Magento 2 in 8 steps
Steps 1–5 and 7–8 happen in the admin. Step 6 adds a small module and needs someone with access to the Magento code — only for checkout on 2.4.7 and later.
- 1Scan your storeRun the free check above on your homepage and a product page, and keep the list of trackers it finds.Free pre-consent scan
- 2Design and save your bannerMatch your theme in the customizer and save it to your store's domain to get the site key. Store views on other domains need a site each.Open the customizer
- 3Switch Cookie Restriction Mode offStores → Settings → Configuration → General → Web → Default Cookie Settings → Cookie Restriction Mode: No. Save, then refresh the invalid caches Magento lists, so visitors see one banner, not two.
- 4Paste the snippet into HTML HeadContent → Design → Configuration → Edit your store view → Other Settings → HTML Head → Scripts and Style Sheets. Paste the snippet at the very top of the field, above anything else, and click Save Configuration. The field is set per store view, so repeat it for every store view that needs the banner.
- 5Put Google tags below itAdobe says the field renders before the closing </head>, so it isn't guaranteed to come first. If Magento's own GA4 (Sales → Google API → Google GTag) or Adobe Commerce's Tag Manager loads before the consent default, switch it off and add your Google tag or container in the same field, below PrivacyPill.
- 6Allow the banner on checkout (2.4.7 and later)Checkout pages enforce the Content Security Policy, and Adobe says JavaScript in the Scripts and Style Sheets field must be whitelisted or it won't run there. Add the three-file module from the section below, then enable it.
- 7Keep 'Move JS code to the bottom of the page' offStores → Configuration → Advanced → Developer → JavaScript Settings — visible in developer mode only; in production check bin/magento config:show dev/js/move_script_to_bottom. When it's on, Magento moves every script, this one included, to the end of the page.
- 8Flush the cache and testSystem → Cache Management → Flush Magento Cache (and your Varnish or CDN cache). Then work through the checklist below in a private window — checkout included.Consent Mode v2 checker
<!-- PrivacyPill: keep this first in <head>, before Google Tag Manager or analytics -->
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag('consent','default',{ad_storage:'denied',ad_user_data:'denied',ad_personalization:'denied',analytics_storage:'denied',functionality_storage:'denied',personalization_storage:'denied',security_storage:'granted',wait_for_update:500});</script>
<script src="https://privacy-pill-consent-studio.lovable.app/api/public/v1/pp.js?site=pp_your_site_key"></script>Replace pp_your_site_key with your site key — you'll get it when you save your banner.
Test checklist: is your Magento banner working?
Run these on the live store in a private window, logged out of the customer account.
| Check | How | Passes when |
|---|---|---|
| One banner on the first visit | Open the homepage | PrivacyPill's banner appears and Magento's Allow notice doesn't |
| Nothing optional before a choice | Run the free scan on your homepage and a product page | No analytics or advertising cookies and no pixel requests before consent |
| Consent defaults come first | The free Consent Mode v2 check, or Google Tag Assistant | A consent default with all four v2 signals denied before gtag.js or the Tag Manager container |
| Checkout runs the banner | Open checkout with the browser console open | The banner script loads, and no Content Security Policy errors name the PrivacyPill host or an inline script |
| Every store view | Switch store views or open each domain | Each one shows the banner in its language |
| Cart works after Reject | Reject, add a product, open the mini cart and checkout | The cart keeps its items |
Magento's own cookies, as Adobe classifies them
Adobe lists Magento's default cookies and browser storage as exempt or non-exempt, and asks merchants to use the list as a guide and consult their legal advisers.
| Name | What Adobe says it does | Type |
|---|---|---|
| PHPSESSID | Tracks user sessions on the storefront | Cookie, exempt |
| form_key | Prevents cross-site request forgery (CSRF) | Cookie, exempt |
| private_content_version, section_data_ids, mage-cache-sessid | Keep customer-specific content (cart, wish list, checkout) out of the page cache and in sync | Cookies, exempt |
| X-Magento-Vary | Tells the cache when a new version of a page is needed — Adobe says not to disable it | Cookie, exempt |
| persistent_shopping_cart | Restores the cart for an anonymous shopper | Cookie, exempt |
| store | Remembers the store view or locale the shopper chose | Cookie, exempt |
| mage-cache-storage, product_data_storage, recently_viewed_product | Visitor-specific shop content, recently viewed and compared products | Local storage, exempt |
| add_to_cart, remove_from_cart | Tell Google Analytics when a product is added to or removed from the cart (Adobe Commerce only) | Cookies, listed as exempt |
| user_allowed_save_cookie | Used for Cookie Restriction Mode | Cookie |
Adobe's list is longer; these are the ones most stores see. Third-party extensions and tags set their own cookies — the free scan shows them.
Magento 2 cookie consent extensions compared
Prices and terms as shown on each vendor's own page on 16 November 2026, in USD. Some vendors price Adobe Commerce editions differently; check the page for your edition.
| Extension | Price shown | Updates and support | Consent Mode v2 |
|---|---|---|---|
| Amasty Cookie Consent (GDPR) | $189, then $115 a year for updates and support | 12 months included; you can cancel and renew later for an extra fee | Listed as compatible |
| Magefan Cookie Consent | $149, no subscription | 365 days of updates and support; renewal at 50% off; keep using your last version | Listed |
| Mirasvit Cookie Consent | $219 for Magento Open Source; Adobe Commerce and Commerce on Cloud add $230 or $460 | One year of support | Listed |
| Mageplaza GDPR | From $79 | One year of support | Lists the ad_user_data signal; no explicit Consent Mode v2 claim |
| PrivacyPill (snippet, not an extension) | Free for one store up to 5,000 pageviews a month; Lifetime €49 once; Pro €9 a month (EUR, excl. VAT) | Lifetime updates; nothing to install or upgrade in Magento | Built in |
Extension or snippet?
- An extension runs inside Magento: it can read Magento's layout and categories, but you install and upgrade it with each Magento release.
- A snippet runs in the visitor's browser: one admin field and, for checkout on 2.4.7+, the small whitelist module on this page — nothing to upgrade when Magento changes.
Checkout and the Content Security Policy (2.4.7 and later)
Since 2.4.7, Magento Open Source and Adobe Commerce run their Content Security Policy in restrict mode on payment pages in the storefront and admin, and in report-only mode everywhere else. On those pages the policy has no unsafe-inline for scripts, and only whitelisted inline scripts run. Adobe adds that the content of the Scripts and Style Sheets field can't be hashed and whitelisted automatically — so without the module below, the banner and its Consent Mode defaults don't run on checkout.
The module allows three things: the PrivacyPill host as a script source, the same host for connect-src (the banner sends each choice to the consent log with sendBeacon), and the inline defaults script by its SHA-256 hash, which is how Adobe's documentation shows inline scripts are whitelisted. Paste the snippet unchanged: if you edit the inline script, its hash changes and checkout blocks it again.
<?php
// app/code/PrivacyPill/ConsentCsp/registration.php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'PrivacyPill_ConsentCsp', __DIR__);
<!-- app/code/PrivacyPill/ConsentCsp/etc/module.xml -->
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="PrivacyPill_ConsentCsp">
<sequence>
<module name="Magento_Csp"/>
</sequence>
</module>
</config>
<!-- app/code/PrivacyPill/ConsentCsp/etc/csp_whitelist.xml -->
<?xml version="1.0"?>
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
<policies>
<policy id="script-src">
<values>
<value id="privacypill-host" type="host">https://privacy-pill-consent-studio.lovable.app</value>
<!-- The inline Consent Mode defaults in the snippet, exactly as pasted -->
<value id="privacypill-defaults" type="hash" algorithm="sha256">gXQiaZPuAoTT0S5sQazJkVglWa+GIUkHKQvu1jmfnpk=</value>
</values>
</policy>
<policy id="connect-src">
<values>
<value id="privacypill-beacon" type="host">https://privacy-pill-consent-studio.lovable.app</value>
</values>
</policy>
</policies>
</csp_whitelist>
# Then, from the Magento root:
bin/magento module:enable PrivacyPill_ConsentCsp
bin/magento setup:upgrade
bin/magento cache:flushThen open checkout with the browser console open: no Content Security Policy message should name the PrivacyPill host or an inline script. If the console also reports style-src, your policy blocks the inline styles the banner draws inside its own shadow DOM. Adobe's payment-page integrity checks (SRI) cover JavaScript files in Magento's own file system, not externally hosted scripts.
Script order in the head
Consent Mode needs its default before any Google tag. Adobe says the Scripts and Style Sheets field is placed before the closing </head> tag, which doesn't guarantee it comes first. Run the free Consent Mode v2 check after installing: if gtag.js or the Tag Manager container loads before the default, move those tags into the same field below PrivacyPill.
Magento's GA4 integration lives in Stores → Settings → Configuration → Sales → Google API → Google GTag. Google Tag Manager as a built-in feature is Adobe Commerce only, in the same section. Adobe's release notes for 2.4.7 and 2.4.8 don't mention Consent Mode for either, so set the defaults with PrivacyPill and let the tags read them.
'Move JS code to the bottom of the page'
This developer setting (config path dev/js/move_script_to_bottom, global scope) takes every script tag in the finished page and moves it to just before </body>. In the 2.4.7 and 2.4.8 source the only scripts it skips are text/x-magento-template, so there's no attribute to keep one script in the head. Keep it off. The setting only shows in the admin in developer mode; on a production store, check it with bin/magento config:show dev/js/move_script_to_bottom.
Hyvä themes
Hyvä uses the same Content → Design → Configuration → HTML Head → Scripts and Style Sheets field, and its docs say to clear the cache after saving it. Hyvä's CSP-compatible themes disallow unsafe-inline, so only explicitly authorised inline scripts run — the whitelist module above authorises the defaults script by hash. Hyvä's registerInlineScript() is for inline scripts in your own templates.
Full page cache and Varnish
The snippet is the same for every visitor — the choice lives in the visitor's browser — so it caches like the rest of the page. Flush Magento's cache and any Varnish or CDN cache after you change the field, and leave Magento's X-Magento-Vary cookie alone: Adobe says disabling it affects system stability.
Running Shopify or WooCommerce too?
The banner and dashboard are the same on every platform. Shopify needs a bridge to its Customer Privacy API, and WooCommerce's Order Attribution waits only through the WP Consent API — each guide covers that.
Frequently asked questions
Sources
Facts on this page come from these pages, read on . Spotted something out of date? Write to kalmwerk@gmail.com and we'll correct it.
- Adobe Experience League: page setup (HTML Head, Scripts and Style Sheets)
- Adobe Experience League: cookie law compliance and default cookies
- Adobe Experience League: Google Analytics (GTag)
- Adobe Experience League: Google Tag Manager (Adobe Commerce only)
- Adobe Commerce 2.4.7 release notes
- Adobe Commerce 2.4.8 release notes
- Adobe developer docs: Content Security Policies
- Adobe Experience League: scripts in design configuration must be whitelisted for checkout
- Adobe developer docs: Subresource Integrity
- Adobe Experience League: Developer configuration (JavaScript settings)
- Magento 2.4.7 source: JsFooterPlugin (move JS to the bottom)
- Hyvä docs: the Scripts and Style Sheets field
- Hyvä docs: CSP compatibility
- Adobe Experience League: lifecycle policy (supported versions)
- Amasty: Cookie Consent (GDPR) for Magento 2
- Magefan: Magento 2 Cookie Consent
- Mirasvit: Magento 2 Cookie Consent
- Mageplaza: Magento 2 GDPR
- EDPB: report of the cookie banner taskforce (January 2023)
Using Google Ads or GA4? Check Consent Mode v2
See whether a consent default runs before your Google tags, what the four v2 signals start as, and how to fix it.
Set up PrivacyPill on other platforms
See all- Shopify cookie bannerTested theme.liquid install, Customer Privacy API, apps compared.
- WooCommerce cookie bannerFree plugin, WP Consent API for Order Attribution, Consent Mode v2.
- Squarespace cookie bannerBuilt-in banner vs real blocking, Code Injection, Consent Mode v2.
- Webflow cookie bannerHead code install, Consent Mode v2, Analyze and Optimize consent.
- Wix cookie bannerWix's own banner vs apps vs custom code, and what each holds back.
- Framer cookie bannerFramer's banner component vs custom code, Consent Mode v2, run once.
- HubSpot cookie bannerHubSpot's banner vs your own, setHubSpotConsent, Consent Mode v2.
- Ghost cookie bannerWhen Ghost needs a banner, Code Injection, embeds and native analytics.
- WordPress cookie bannerWPCode or functions.php, classic and block themes.
- Lovable cookie bannerOne prompt to the Lovable agent, or one tag.
- Bolt cookie bannerOne prompt to the Bolt agent, then publish.
- v0 cookie bannernext/script in the root layout, publish to Vercel.
- Next.js cookie bannernext/script beforeInteractive in the root layout.
Try it on your own site
Design your banner, preview it live, and paste one line. Free for one domain.