How to implement Cookie Consent for GTM & Google Analytics in Magento Under GDPR?
Implement cookie consent for GTM & GA4 in Magento under GDPR. Step-by-step guide using Google Consent Mode v2 to avoid fines and maintain analytics.
€20 million fines or 4% of revenue - that’s the legal exposure Magento stores face when Google Tag Manager fires before cookie consent, according to General Data Protection Regulation (GDPR).
While GDPR covers all personal data, this violation is specific: cookie consent for GTM, Google Analytics, and marketing pixels. A 2023 German court ruled that even loading GTM requires prior consent, yet most Magento stores fire tracking immediately before banners appear. Therefore, each unconsented pageview multiplies your legal exposure.
This guide addresses the cookie consent piece of GDPR, and how GDPR & Google Analytics compliance makes a difference on your site, protecting both your legal standing and customer trust.

GDPR’s cookie consent requirements come from two regulations working in tandem: the General Data Protection Regulation (Article 6 and 7) and the ePrivacy Directive (the “Cookie Law”). Together, they establish five core requirements that every Magento store must meet.
You must obtain user consent before any non-essential cookies are set or tracking begins:
What this means for Magento stores:
Your Google Analytics code cannot run until users have explicitly agreed to analytics tracking.
Active opt-in is mandatory:
Common violation: Cookie banners that say “By continuing to browse, you consent to cookies.” This doesn’t meet GDPR’s standard. Users must actively opt-in, not passively accept through inaction.
Users must be able to consent to different types of cookies separately, not just accept or reject everything.
Some required cookie categories include:
What this means for Magento stores:
Your cookie consent banner must offer separate choices for each category. Users should be able to accept analytics but reject marketing, or vice versa. A simple “Accept All / Reject All” approach doesn’t meet the granular control requirement.
Each tag in your GTM container must be mapped to a specific category. Your Google Analytics tag should only fire if users consent to analytics. Your Facebook Pixel should only fire if users consent to marketing.
Users must receive clear, specific information about what cookies do and who receives their data.
Cookie Purpose
Don’t say: “We use cookies to improve your experience.”
Do say: “Analytics cookies help us understand which pages visitors view most often and how they navigate our site.”
Third-Party Recipients
You must name the companies that receive data:
Data Collected
Be specific about what’s tracked:
Storage Duration
Explain how long cookies persist:
Link to full privacy policy: The banner should include a prominent link to your complete privacy policy where users can read comprehensive details about data processing.
What this means for Magento stores:
Your cookie consent banner needs more than a generic message. Each cookie category should have a detailed description explaining exactly what happens when users accept it. Many Magento extensions provide templates, but you should customize them to accurately reflect your specific tracking setup.
Users must be able to withdraw consent as easily as they gave it, and withdrawal must immediately stop tracking.
What this means for Magento stores:
You need a persistent way for users to change their cookie preferences. The consent banner can’t just appear once and never again. Many Magento stores fail this requirement by only showing the banner on first visit, with no way for users to later revoke consent.
You must keep records of when and how users provided consent.
What this means for Magento stores:
You need a database table or system to store consent records. This isn’t just good practice—it’s your proof of compliance if regulators investigate. Without consent logs, you cannot demonstrate that you obtained valid permission before tracking users.

GDPR Article 6 is crystal clear: you need a lawful basis for processing personal data. For non-essential tracking like analytics, that basis is prior consent.
“Prior consent” means:
Google Tag Manager is a container system that manages and fires multiple tracking technologies from one central location. It acts as a “wrapper” that loads other tracking scripts like Google Analytics, Facebook Pixel, remarketing tags, and conversion trackers. GTM itself doesn’t create cookies directly, but the tags GTM fires (GA, pixels, heat maps) do.
In most Magento installations, GTM is configured to fire all its tags immediately when the page loads. This means Google Analytics starts tracking users the instant they land on your site before they ever see a cookie consent banner, let alone accept it.
When Google Analytics fires without user consent, it immediately begins collecting what GDPR classifies as personal data:
When Magento stores only rely on the basic features of default setup, it is likely for them to fail the regulations:

Using Mageplaza GA4 extension will ensure the proper sequence:
Implementing GDPR-compliant Google Analytics tracking in your Magento store takes just a few configuration steps with Mageplaza’s Google Analytics 4 extension. Here’s your step-by-step guide to setting up cookie consent that actually works.

Use Mageplaza Magento 2 Google Analytics extension for a ready-made solution.
After downloading & installing, go to:
Stores > Configuration > Mageplaza Extensions > Google Tag Manager
to Enable the module.
This is the most important configuration for GDPR & Google Analytics compliance. The Consent Version setting determines how your store handles cookie consent for analytics tracking.
You’ll see three options, but only one meets current GDPR and Google requirements.

Option 1: No Consent Mode ❌ Not Recommended
Cookies collect data without asking for user permission. Google Analytics tracks all visitors immediately on page load with no consent banner.
When to use: Only if you exclusively serve non-EU markets with no cookie consent requirements.
Option 2: Google Consent v1 ⚠️ Outdated
If you select Consent version = Google consent v1, you only implement the basic consent framework with limited consent signals.
However, Google’s 2024 policy change means v1 no longer supports collecting new user data from European Economic Area (EEA) visitors. You’ll have significant data gaps for EU traffic, exactly the audience where compliance matters most.
Option 3: Google Consent v2 ✅ Recommended
If you select Consent version = Google consent v2, you implement Google’s latest consent framework with full GDPR compliance and complete EEA data collection capability when users consent.
When you select this option, two new configuration fields appear below: Frontend Consent Popup Content and Cookies Validity Period.
After enabling Consent Mode v2, you’ll see the Frontend Consent Popup Content editor. This is where you customize the consent banner your customers will see.

The popup content editor allows you to customize:
💡 Best Practices for Popup Content
Once configured, the consent popup automatically appears in two scenarios: for first-time visitors and when the consent is expired.
Here’s how it looks on the frontend:

The popup presents two types of GTM cookies for users to control:
Analytics Cookies
Advertisement Cookies
Users can toggle each category independently, providing the granular control of Google Analytics that GDPR requires.
| User Action | What Happens | Tracking Result | Your Analytics |
|---|---|---|---|
| Close Popup (no selection) |
All optional cookies auto-rejected
Only necessary cookies active
|
❌ GA4 blocked
❌ Ads blocked
|
No data. Default-deny prevents implied consent. |
| Reject All |
Explicit rejection logged
No tracking cookies set
|
❌ GA4 blocked
❌ Ads blocked
|
No data. Privacy right enforced and logged. |
| Accept All |
Full consent granted
All tracking enabled
|
✅ GA4 active
✅ Ads active
|
Complete tracking + remarketing capability. |
|
Custom Selection (e.g., Analytics only) |
Only chosen categories activate
Granular consent applied
|
✅ GA4 active
❌ Ads blocked
|
Behavioral data without remarketing. |
The final configuration determines how long user consent remains valid before requiring re-confirmation.

Mageplaza Google Analytics 4 extension automatically enforces the maximum 365-day limit required by the EU’s ePrivacy Directive. However, Magento stores can select a range from 1 to 365 days.
💡 Tip: Start with 180 days. This balances compliance with user experience. Monitor your consent acceptance rates and adjust based on customer feedback.
When the validity period ends, the GTM consent cookie is deleted from the user’s browser. Next visit triggers popup to reappear, and users undergo the same process to reconfirm choices. This automatic expiration ensures ongoing, fresh consent without manual intervention.
Click Save Config in your Magento admin. Then start testing with a simple checklist as follows:
👉View detailed guide on how to add GA4 to Magento 2
If your Magento store uses Google Tag Manager and serves EU customers, cookie consent isn’t negotiable. Most stores know they need consent but struggle with the technical challenge: connecting cookie banners to GTM so tags actually wait for user approval.
Mageplaza Google Analytics 4 with GTM eliminates this complexity through built-in Google Consent Mode v2, giving you compliant tracking without custom coding. You get legal protection, customer trust, and full analytics when users consent. Install the extension and turn a legal liability into a competitive advantage with simple admin configuration.