Key points
- A banner is only worth something if it actually blocks trackers before the visitor chooses: that’s the flaw we find most often.
- Start with an inventory of what your site sets and contacts, in a private window, before buying or configuring anything.
- Google Consent Mode adjusts how Google’s tags behave based on the visitor’s choice; it replaces neither the banner nor the blocking of other scripts.
“We’ve got a cookie banner, so we’re compliant.” We hear it in nearly every audit, and it’s rarely true. On a good share of the sites we take over, the banner looks fine and offers “Accept” and “Reject”… while Google Analytics, the ad pixel and the YouTube video on the home page have already loaded in the background. The banner is decoration. This guide is for business owners and marketing leads who want to know what their site concretely has to do, and for the teams who’ll build it: what the rules ask for, how to check your own site in a few minutes, how to set up Google Analytics without losing all your data, and how to fit it into WordPress without breaking caching or the design. One important caveat: we’re a technical agency, not a law firm. For special cases (health data, children, data leaving Europe), have your policy reviewed by a lawyer.
What the rules actually require
Under the European rules (the GDPR together with the ePrivacy rules on cookies, with close equivalents in the UK), the principle is simple: a site may only store or read on a visitor’s device what is strictly necessary for it to work, unless the visitor has agreed. Consent has to come first, be freely given and informed, and be as easy to withdraw as to give. Data protection authorities have published detailed guidance on cookies, and several of them regularly fine sites that ignore it.
For your website, that boils down to a handful of very testable requirements:
- no tracker that needs consent may load before the visitor has chosen;
- rejecting must be as easy as accepting: a “Reject all” button on the same level as “Accept all”, not buried behind a “Settings” link;
- no pre-ticked boxes, and carrying on browsing doesn’t count as agreement;
- visitors must be able to change their mind at any time, for instance through a “Cookie settings” link in the footer;
- your cookie policy must state plainly who sets what, and why.
What’s exempt: the session cookie that keeps someone logged in, a shop’s basket, security protections, load balancing, and the cookie that stores the visitor’s consent choice itself. Some regulators also exempt certain analytics tools when they’re configured in a restricted, privacy-friendly way, under conditions they spell out; Google Analytics in its standard setup doesn’t qualify.
Take inventory: what your site really sets
Before picking a tool, you need to know what it will have to handle. On our projects, the inventory nearly always turns up surprises: an old pixel added by a previous agency, a Google Map in the footer, a chat widget, a social sharing plugin quietly loading scripts from three networks.
It takes a few minutes. Open your site in a private window without clicking the banner. In the browser’s developer tools (F12), the Application tab, or Storage depending on the browser, lists cookies and local storage. The Network tab shows every request sent. You can also paste these lines into the console:
// Browser console, in a private window, BEFORE touching the banner
// 1. Cookies readable by JavaScript that are already set
document.cookie.split('; ').filter(Boolean)
.forEach(c => console.log(c.split('=')[0]));
// 2. Third-party domains the page has already contacted
[...new Set(performance.getEntriesByType('resource')
.map(r => new URL(r.name).hostname)
.filter(h => h !== location.hostname))]
.forEach(h => console.log(h));
The first part won’t show cookies flagged HttpOnly, which only appear in the Application tab, but it’s enough to spot analytics and advertising cookies. The second lists the third-party domains contacted. If Google Analytics, ad networks or social networks already show up when you haven’t accepted anything, your banner isn’t blocking what it should.
Repeat this on several page templates: home, blog post, contact, product page. Scripts are often only loaded where a block uses them. For each service, write down its purpose (analytics, advertising, embedded content, core functionality): that list becomes the basis for your consent categories and your cookie policy.
Flaw number one: a banner that blocks nothing
Most broken banners we come across share the same issue: the tracking code is pasted into the theme header, or injected by a plugin, and runs as soon as the page opens. The banner sits next to it, dutifully recording the visitor’s choice and preventing nothing.
The right approach is to make every consent-dependent script inert to begin with, then switch it on only once the visitor agrees. The most reliable way is to change its type, since browsers don’t execute a <script type="text/plain">.
<!-- Before: loaded for everyone, as soon as the page opens -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<!-- After: inert until the category has been accepted -->
<script type="text/plain" data-consent="statistics"
data-src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
When the visitor accepts a category, a small script swaps those inert tags for real ones, which then load normally. The same script replays earlier choices on every new page:
function enableScripts(category) {
document
.querySelectorAll(`script[type="text/plain"][data-consent="${category}"]`)
.forEach(placeholder => {
const s = document.createElement('script');
if (placeholder.dataset.src) {
s.src = placeholder.dataset.src;
s.async = true;
} else {
s.textContent = placeholder.textContent;
}
placeholder.replaceWith(s); // a script created this way runs when inserted
});
}
// On every page load: replay the choices already made
let choices = {};
try { choices = JSON.parse(localStorage.getItem('consent')) || {}; } catch (e) {}
Object.keys(choices).filter(c => choices[c] === true).forEach(enableScripts);
That’s exactly what serious consent management platforms do under the hood. If you use one, make sure it works this way, with prior blocking, and doesn’t just “clean up” cookies afterwards: a cookie deleted after it was set has already been read.
Two traps come up again and again. The first is a blocked script that something else depends on, such as inline code calling gtag() before gtag.js exists. Give both the same category and keep them in order. The second is optimisation tools that combine or defer scripts. They can rewrite your tags and drop the type attribute along the way. Always test blocking with optimisation switched on, exactly as in production.
Google Analytics and Consent Mode, without losing all your data
Google Consent Mode is widely misunderstood. It isn’t a banner, and it doesn’t make a site compliant on its own. It’s a mechanism that tells Google’s tags (Analytics, Ads, Tag Manager) what the visitor chose, so they can change how they behave. Google now requires advertisers targeting users in Europe to pass these consent signals, which makes it unavoidable as soon as you run Google Ads.
It’s set up in two steps: a default state, fully denied, declared before any Google tag loads, then an update sent by your banner when the visitor accepts.
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
// 1. Everything denied by default: place this BEFORE gtag.js or Google Tag Manager
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
wait_for_update: 500
});
</script>
<script>
// 2. Called by your banner when the visitor accepts analytics
gtag('consent', 'update', { analytics_storage: 'granted' });
</script>
There are two ways to run it. In “basic” mode, Google’s tags don’t load at all until the visitor accepts: that’s the easiest setup to defend. In “advanced” mode, the tags load straight away but, if the visitor declines, send cookieless signals that Google uses to model the missing conversions. Advanced mode gives you better numbers, but it means requests reach Google before anyone has chosen. Make that call deliberately, ideally with whoever handles compliance in your company.
Expect your Analytics numbers to drop once blocking actually works. That’s not a bug: you’ve stopped measuring people who decline, whereas before you were measuring everyone without the right to. Warn your marketing team before going live, add an annotation in Analytics on that date, and compare trends rather than raw volumes.
On WordPress: plugins, custom code and the caching trap
On WordPress, the usual route is a consent management plugin. What we check before choosing one: real prior blocking of scripts, a reject button on the same level as accept, support for Google Consent Mode, the ability to add your own services, a link to reopen the settings, and a reasonable weight on the page.
When the site loads its own tracking scripts from the theme or a custom plugin, we prefer to neutralise them at the source rather than rely on detection. The script_loader_tag filter turns a tag registered with wp_enqueue_script() into an inert one, which the activation script above will wake up:
// Custom plugin: neutralise tracking scripts until a choice has been made
add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
$categories = [
'agency-analytics' => 'statistics',
'agency-pixel' => 'marketing',
];
if ( ! isset( $categories[ $handle ] ) ) {
return $tag;
}
return sprintf(
'<script type="text/plain" data-consent="%s" data-src="%s"></script>' . "n",
esc_attr( $categories[ $handle ] ),
esc_url( $src )
);
}, 10, 3 );
Note that inline code added with wp_add_inline_script() is printed in a separate tag this filter doesn’t touch: if it depends on the blocked script, block it the same way or move it into the file itself.
The trap that cost us the most time is caching. It’s tempting to check consent in PHP, for example with the wp_has_consent() function provided by the WP Consent API plugin, and only print tracking code for visitors who agreed. But with a page cache, whether it’s a plugin, your host’s cache or a CDN, the first version generated is served to everyone. Depending on who came first, either nobody is tracked or everybody is. On a cached site, the decision to load a tracker has to be made in the browser, in JavaScript, based on the choice stored locally.
Videos, maps and social embeds: load on click
Embedded content is the most overlooked source of trackers. A YouTube video, a Google Map or an embedded Instagram post loads the third party’s code, which can set its own cookies as soon as the page appears, even if the visitor never presses play.
On most sites we use a “facade”: an image and a button in place of the player, which only load the third-party service when clicked and explain what will happen. That click is an explicit choice for that specific piece of content.
<div class="video-deferred" data-youtube="VIDEO_ID">
<button type="button">
Play the video (hosted by YouTube, which may set cookies)
</button>
</div>
<script>
document.addEventListener('click', e => {
const button = e.target.closest('.video-deferred button');
if (!button) return;
const box = button.parentElement;
const iframe = document.createElement('iframe');
iframe.src = 'https://www.youtube-nocookie.com/embed/'
+ encodeURIComponent(box.dataset.youtube) + '?autoplay=1';
iframe.title = 'YouTube video';
iframe.allow = 'autoplay; encrypted-media; picture-in-picture';
iframe.allowFullscreen = true;
box.replaceChildren(iframe);
});
</script>
The youtube-nocookie.com domain reduces what YouTube stores before playback, but not once the video is playing, so it doesn’t replace the facade. Host the preview image on your own server rather than pulling it from YouTube, or the preview itself already contacts a third party.
Check before and after going live
A consent setup gets tested like any other feature, and re-tested every time a service or plugin is added. Here’s the list we run through, in a private window, on a desktop and on a phone:
- before any click: no analytics or advertising cookies, and no requests to tracking domains in the Network tab;
- after “Reject all”: the same, across several pages, and the banner doesn’t come back on every page;
- after “Accept all”: your tools do record visits, which you can confirm with Tag Manager’s preview mode or Analytics’ real-time report;
- the “Cookie settings” link reopens the choices, and withdrawing consent really stops tracking on the following pages;
- the cookie policy lists the services actually present, not those of a generic template;
- the banner works with a keyboard, reads well on mobile, and doesn’t cover so much content that the page becomes unusable.
FAQ
Do I need a banner if my site uses no analytics or advertising tools?
If your site only sets strictly necessary cookies, such as a session or a basket, no consent is required and a banner isn’t mandatory. Confirm it with the inventory described above: embedded content and some plugins set trackers without you knowing. You still need to explain what you use in your privacy policy.
My traffic numbers dropped after fixing consent. Did I break something?
Probably not. You’ve stopped measuring visitors who decline, which is the expected behaviour. Just check that visitors who accept are counted, using the real-time report, then focus on trends rather than volumes.
Do WooCommerce cookies need consent?
The cookies that run the basket and checkout session are strictly necessary and don’t. Conversion tracking, remarketing or review tools added to the shop, on the other hand, usually fall into the categories that require consent.
Want to know what your site really sets? We audit your setup, fix tracker blocking and integrate a compliant banner that keeps your site fast and your measurement meaningful.



