How to add a cookie consent banner to a Shopware 6 store
In Shopware 6, add the snippet from a theme plugin that extends the storefront's meta.html.twig, in the head block that holds the tracking scripts. Then switch off "Use default cookie notification" under Settings, then General, then Basic information, so the built-in consent manager no longer shows, and move the Google tag out of the sales channel's analytics settings, because that tag waits for Shopware's own consent cookie.Steps
Where to paste the snippet in Shopware 6
Shopware 6 has no Administration field for head code. Scripts in the head come from the storefront template layout/meta.html.twig, which you extend from your theme or a small plugin, the way Shopware's developer documentation describes for script tags. The block layout_head_javascript_tracking holds the tracking scripts Shopware prints itself, so the snippet goes there, before them:
twig{# <plugin root>/src/Resources/views/storefront/layout/meta.html.twig #}{% sw_extends '@Storefront/storefront/layout/meta.html.twig' %}{% block layout_head_javascript_tracking %}<script src="https://cookiequiet.com/cq.js" data-site="YOUR_SITE_KEY" data-consent-mode="1" data-auto-block="1" defer></script>{{ parent() }}{% endblock %}
Keep {{ parent() }}: without it, the block's original content would not render. Install and activate the plugin if it is new, then clear the cache (bin/console cache:clear). Shopware Store extensions that add code to the head do the same job without a plugin of your own, as long as they print it in the head.
How to turn off Shopware's cookie consent manager
Shopware ships its own cookie consent manager, with the categories Technically required, Comfort functions, Statistics and Marketing. In current Shopware 6 versions, the switch is in the Administration: Settings, then General, then Basic information, card Legal and compliance, option Use default cookie notification. Shopware's help text says to deactivate it only when you use a third-party solution, which is the case here. Turn it off and save, so visitors see one banner.
Shopware's own cookies stay: the session- cookie for the cart and login and timezone are technically required, and cookie-preference and cookie-config-hash (30 days) belonged to the built-in manager. The free cookie scanner lists what your extensions add.
What happens to Shopware's Google Analytics integration?
The Google Analytics ID you enter in a sales channel's analytics settings is printed by Shopware itself. Its template sets Google's consent defaults to denied and only loads the tag once Shopware's own consent cookie for Google Analytics is set, which its consent manager writes. With that manager off, the integration stays silent. Two options:
- Paste the tag yourself. Remove the ID from the sales channel and add the Google tag to the same block, after the snippet, marked so it runs only with analytics consent:
html<script type="text/plain" data-cq-category="analytics" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script><script type="text/plain" data-cq-category="analytics">window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-XXXXXXX');</script>
- Use Google Tag Manager for e-commerce events, with Consent Mode fed by
data-consent-mode="1", as in the Google Tag Manager guide.
Other extensions that register their cookies with Shopware's consent manager and wait for it should be checked one by one: either the extension lets you load it unconditionally (then mark its script or let the auto-blocker hold it), or it keeps waiting for a consent that no longer comes. Scripts injected with JavaScript from about 80 known trackers are held by Cookiequiet's auto-blocker until their category is granted; see blocking scripts until consent.
How to add the Cookie preferences link
Shopware's own FAQ uses a link category for its cookie settings, and the same works for Cookiequiet: Catalogues, then Categories, create a category named "Cookie preferences", set its type to Link, the link type to External, switch off the protocol option and enter #cq-preferences as the target. Activate it and place it in the footer navigation. Cookiequiet opens the preferences centre from any link with that address.
How to test
- Open the storefront in a private window. Shopware's cookie bar should be gone and Cookiequiet's banner shown.
- Click Reject all and check the cookies:
cq_consent, thesession-cookie, and no_gaor_fbp. - Add a product to the cart and open the checkout: the session cookie keeps the cart.
- Clear the cookies, click Accept all, reload: the marked tags run. Check the consent log in the dashboard.
Cookiequiet is free for one store with geo-targeting included, and Starter is €3 per website per month with no pageview limit, see pricing.
Questions
Sources
- Shopware Developer: Add JavaScript as script tag (extending meta.html.twig)
- Shopware source: storefront layout/meta.html.twig
- Shopware source: Basic information settings (useDefaultCookieConsent)
- Shopware Developer: Cookie consent management
- Shopware Docs: Cookie Consent Manager FAQ
- Shopware source: storefront analytics template (Google consent defaults)