Google Consent, Drupal, and You

By Jordan , 5 March, 2025

I recently wrestled with the new Google Consent layer while building a new website.  Here's my story.

Why Bother

Short answer: you probably don't need this. I was able to do basic Google Analytics without Google Tag Manager or Consent, and it worked just fine.

Long answer: I needed this because my boss wanted custom variables in Google Analytics. The way to pass those variables is through GTM.  You need to hook up the telemetry (with custom dimensions), but you also need consent from your users.

How to Do It

For your Drupal site, you need only two moving parts:

  1. The Google Tag module
  2. The Consent Manager module

Install and enable both using the normal methods.  Optional: patch the Google Tag module, in order to add Google Consent v2 support.

You will also need to set up several external accounts, to connect all the moving pieces:

  1. Google Analytics
  2. Google Tag Manager
  3. Consent Manager (note: this is a paid, 3rd party service)

For each service, you'll need to register and configure your website.  Both the Google Tag module, and the Consent Manager module, require configuration after you've registered with those services.

Assuming you configured GTM and Consent Manager correctly, you are now streaming data to Google Analytics.  Congratulations!  Now, you can create your custom variable.

Drupal: Create a Dimension

Log in to your Drupal site as an administrator, then visit the Google Tag admin page: /admin/config/services/google-tag. Once there, scroll to the "Custom dimensions and metrics" section and click Add new parameter. You need to choose whether you're creating a dimensions or a metric.  When in doubt, choose dimension.  The name should be human-friendly.  For the value field, click the Browse available tokens link for a list of options.

Scroll down and click Save at the bottom of the page when finished.

GTM: Add a Dimension

The next two steps involve Google Tag Manager and Google Analytics directly.  Google has a fantastic help article on Creating user-scoped custom dimensions.  Here's a summary:

  1. Visit GTM and create the Dimension based on the name you chose earlier
  2. "Submit" the GTM changes to publish a new version
  3. Go to Google Analytics and define your new Dimension there
  4. Create data visualizations in GA to view your new Dimension in action

Some notes to remember:

  • Data will take a few minutes to start flowing, even if you have an active user base
  • You can use the Tag Assistant to test your telemetry

What's Wrong with Free?

In other words: "Why use a paid service?"  If you've read my blog before, you know I'm all about FOSS.  So, let's look at the two free options for Drupal, and see why they don't stack up.

Cookies

The COOKiES Consent Management module is most popular module on Drupal.org to handle consent management.  However, Google released version 2 of their Consent api last year, and the Cookies module hasn't caught up yet.  (There is an issue open for this, with a patch, but it wouldn't work in my testing.)

Klaro

Not only is Klaro also popular, but it was recently chosen to be the consent solution for Drupal CMS.  Impressive... but I couldn't get it to work either.  (There are multiple open issues for this, with patches... but they didn't work in my real-world tests.)

Enter consentmanager.net.  They are a paid service with a free tier, and they provide a contrib module for Drupal.  I was able to get it working quickly and easily, and they didn't even ask for a credit card.  This is definitely my preferred solution for commercial websites.

Comments

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.