Magento 2 cookie consent

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.

Design your banner free

Facts checked · Sources

What Adobe documents for Magento's built-in option, next to what PrivacyPill adds.

Magento Cookie Restriction ModePrivacyPill
What visitors seeA message that cookies are required for full-featured operation, a privacy policy link and an Allow button; Adobe doesn't describe a reject optionAccept all and Reject all side by side, plus preferences by category
Where it appearsDepends on the theme — above the header, below the footer or elsewhereFloating pill, bottom bar, modal or corner badge, styled in the customizer
What waits for consentMagento's Google Analytics doesn't collect data until visitors accept, Adobe says; other trackers aren't covered in its descriptionAny script marked type="text/plain" with data-pp-category; Google tags through Consent Mode v2
Google Consent Mode v2Not mentioned in the 2.4.7 or 2.4.8 release notesDefaults denied in the head, updated on every choice
Record of the choiceThe user_allowed_save_cookie cookieEvery choice logged pseudonymously with the banner version, exportable as CSV
PriceIncluded in Magento Open Source and Adobe CommerceFree 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.

  1. 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
  2. 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
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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
HTML · Content → Design → Configuration → HTML Head → Scripts and Style Sheets (top)
<!-- 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.

CheckHowPasses when
One banner on the first visitOpen the homepagePrivacyPill's banner appears and Magento's Allow notice doesn't
Nothing optional before a choiceRun the free scan on your homepage and a product pageNo analytics or advertising cookies and no pixel requests before consent
Consent defaults come firstThe free Consent Mode v2 check, or Google Tag AssistantA consent default with all four v2 signals denied before gtag.js or the Tag Manager container
Checkout runs the bannerOpen checkout with the browser console openThe banner script loads, and no Content Security Policy errors name the PrivacyPill host or an inline script
Every store viewSwitch store views or open each domainEach one shows the banner in its language
Cart works after RejectReject, add a product, open the mini cart and checkoutThe 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.

NameWhat Adobe says it doesType
PHPSESSIDTracks user sessions on the storefrontCookie, exempt
form_keyPrevents cross-site request forgery (CSRF)Cookie, exempt
private_content_version, section_data_ids, mage-cache-sessidKeep customer-specific content (cart, wish list, checkout) out of the page cache and in syncCookies, exempt
X-Magento-VaryTells the cache when a new version of a page is needed — Adobe says not to disable itCookie, exempt
persistent_shopping_cartRestores the cart for an anonymous shopperCookie, exempt
storeRemembers the store view or locale the shopper choseCookie, exempt
mage-cache-storage, product_data_storage, recently_viewed_productVisitor-specific shop content, recently viewed and compared productsLocal storage, exempt
add_to_cart, remove_from_cartTell Google Analytics when a product is added to or removed from the cart (Adobe Commerce only)Cookies, listed as exempt
user_allowed_save_cookieUsed for Cookie Restriction ModeCookie

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.

ExtensionPrice shownUpdates and supportConsent Mode v2
Amasty Cookie Consent (GDPR)$189, then $115 a year for updates and support12 months included; you can cancel and renew later for an extra feeListed as compatible
Magefan Cookie Consent$149, no subscription365 days of updates and support; renewal at 50% off; keep using your last versionListed
Mirasvit Cookie Consent$219 for Magento Open Source; Adobe Commerce and Commerce on Cloud add $230 or $460One year of supportListed
Mageplaza GDPRFrom $79One year of supportLists 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 MagentoBuilt 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 + xml · whitelist module (three files)
<?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:flush

Then 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.

Shopify cookie banner guideWooCommerce cookie banner guide

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.

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

Try it on your own site

Design your banner, preview it live, and paste one line. Free for one domain.