Skip to main content
Back to Guides
Setup5 min readBy Armin Zaribaf

Cookie Consent on Drupal: Klaro and the Modules

Drupal core has no cookie banner, so consent comes from a contrib module. In 2026 the default has shifted: EU Cookie Compliance is minimally maintained and points users to Klaro, which the new Drupal CMS adopted.

Drupal core ships no cookie banner. Every consent feature is a contrib module, and in 2026 the module you'd reach for has changed. The long-running EU Cookie Compliance module is now minimally maintained, and its own project page tells you to look at Klaro, which was chosen as the consent module for the new Drupal CMS distribution.

Place the CookieBeam loader as the first element in <head>, loaded synchronously before GTM, analytics, or other scripts. Do not add async or defer, and exclude it from script-delay optimizers.

Why the recommendation shifted to Klaro

The EU Cookie Compliance module is flagged minimally maintained and maintenance fixes only on its project page. For Drupal 7 and 10+, it continues to be maintained; sites on Drupal 8, 9, or 10 before 10.2 should consider upgrading to a version that supports Klaro. The Klaro module is used in the new Drupal CMS, so it's the natural starting point for new builds (EU Cookie Compliance on Drupal.org).

Klaro wraps the open-source Klaro! JavaScript library. You define services (Google Analytics, Matomo, an embedded YouTube player), group them by purpose, and the module sets the required HTML attributes on external resources so the library can block them until the visitor consents (Klaro on Drupal.org). Per Klaro's configuration docs, each service can also have a callback function that runs each time that service's consent state changes (Klaro configuration docs).

How Klaro blocks scripts

Klaro takes the same approach a good CMP does: it neutralizes a managed script tag (switching it so the browser won't run it) and activates the service only after consent. You register each service in configuration, describe what it does, and assign it a purpose. When a visitor accepts a purpose, Klaro releases the matching services and fires their callbacks.

One Drupal-specific point: Drupal caches rendered pages aggressively. The consent decision has to stay client-side so a cached page still respects the visitor's current choice. Klaro handles this because its gate runs in the browser, not in the render layer. Test with your page cache and dynamic page cache both on, the way production runs.

Setting up a Klaro service

The workflow is straightforward once the module is in place. Install it with Composer (composer require drupal/klaro), enable it, then open Klaro's settings under the site's Configuration area. You add one service per tool: give it a machine name, a human label, a description, and assign it to a purpose like analytics or marketing. Klaro sets the attributes on external resources that the library needs to block them until that service is accepted, and each service can have a callback function (per Klaro's configuration docs) that runs whenever that service's consent state changes, letting you run custom logic when a visitor updates their choice. Common services on a Drupal site go well beyond Google Analytics: an embedded YouTube or Vimeo player sets cookies, Google Maps sets cookies, social sharing widgets set cookies, and reCAPTCHA on a Webform contacts Google on load. Each of those is a service you register and gate, or an embed you let Klaro replace with a click-to-load placeholder.

Other Drupal options

Klaro isn't the only choice. The COOKiES module and CookieYes both have Drupal integrations, and plenty of sites embed a hosted consent platform instead of managing module configuration per site. If you run a fleet of Drupal sites, or you need cookie scanning and stored consent records across all of them, a hosted embed is often less to maintain than tuning Klaro's service list on every property.

If you run Google Ads or GA4 for EEA or UK visitors, you need Consent Mode v2, required since March 2024. Set the gtag consent defaults to denied before any Google tag loads, then push an update from your consent tool's accept callback (or through Google Tag Manager):

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('consent', 'default', {
    ad_storage: 'denied',
    analytics_storage: 'denied',
    ad_user_data: 'denied',
    ad_personalization: 'denied',
    wait_for_update: 500
  });
</script>

Klaro handles the browser-side gate well, but by default it doesn't keep a server-side log of who consented, to what, and when. Article 7 of the GDPR says you have to be able to demonstrate consent, and a cookie on the visitor's machine storing their choice isn't the same as an audit trail you can produce months later if a regulator asks. If your risk profile calls for proof (a regulated sector, heavy EU traffic, a history of complaints), either add a Drupal module that logs consent events to the database or use a hosted platform that stores timestamped records for you. The proof of consent guide covers what a defensible record looks like.

Embedding a CMP instead

To use a CDN-loaded consent platform on Drupal, add the loader to the page head. You can put it in your theme's html.html.twig, add it through a module like Asset Injector, or place it in a block region that renders in the head. It has to come before your analytics and marketing tags:

<!-- Head: load the consent script FIRST, before any tag -->
<script src="https://cdn.cookiebeam.com/banner/YOUR_BANNER_ID/default/loader.js"></script>

CookieBeam then holds any tag you mark with type="text/plain" and a data-category until the visitor opts in, scans your published pages to keep the cookie policy accurate, and stores a timestamped consent record so you can demonstrate consent when asked.

Test checklist

  • Load a page from a fresh EU-IP private window with caching on, and check Application › Cookies before clicking. Only strictly necessary cookies should exist.
  • Reject and confirm no analytics or marketing cookies appear.
  • Accept and confirm the services activate.
  • Re-run an audit after adding any module that embeds third-party content.

For a broader comparison of tools and approaches, see the CMP comparison and the GDPR cookie checklist.

Competitor information comes from each vendor’s public website and public certification lists as of the review date. Products and prices change, so check the vendor’s own site before you decide. Product names are trademarks of their owners; CookieBeam is not affiliated with them. If something here is out of date, tell us and we will correct it.

6 min read

Manage CookieBeam from ChatGPT or Claude

Connect an AI assistant to your CookieBeam account over MCP and manage banners, scans and analytics from a conversation. Covers connecting, what the assistant can do, example prompts, access control and known limits.

8 min read

Shopify Cookie Consent: GDPR and CCPA Setup Guide for 2026

Shopify's built-in cookie banner covers the basics, but falls short for stores selling into the EU, California, or multiple regions at once. This guide walks through what Shopify gives you, where it stops, and how to add a proper consent layer with CookieBeam.

4 min read

Remix Cookie Consent: Server-Side Rendering and GDPR

Add GDPR-compliant cookie consent to a Remix app. Covers script placement in root.tsx, streaming SSR considerations, consent-aware loaders, and the framework-specific quirks that trip up most implementations.