In this learning track "How to implement consent mode with Cookiebot", I will guide you on how to quickly implement Google Consent Mode v2 using Cookiebot and Google Tag Manager. In previous articles I've already walked you through the step-by-step process of implementing Cookiebot. If you've succesfully followed these articles, Cookiebot will regularly scan your website to determine which cookies are being loaded. However, this traffic pollutes your GA4 data if you don't exclude it. In this article, I'll therefore help you exclude this traffic in GA4.
Table of contents:
Option 1: Exclude Cookiebot's IP Addresses Option 2: Exclude Cookiebot’s User AgentOption 1: Exclude Cookiebot's IP Addresses
Step 1: Define Cookiebot’s IP Addresses as Internal Traffic
- Navigate to: Admin > Data Settings > Data Streams.
- Click on Configure Tag Settings.
- Click on Show More.
- Select Define Internal Traffic.
- Click on Create.
- Choose a name for the filter, e.g.,
Cookiebot Crawler
. - Under traffic_type, enter:
Cookiebot_traffic
. - Add the following IP addresses and select the option IP address matches regular expression:
^(20\.223\.9\.138|34\.(107\.102\.47|141\.10\.24|159\.(86\.126|168\.195|247\.222))|35\.(198\.(78\.207|137\.6|160\.49)|246\.(143\.2|191\.14)))$
- Click Create in the top-right corner.
- This filter should exclude the following IP addresses:
20.223.9.138
34.107.102.47
34.141.10.24
35.198.78.207
34.159.86.126
34.159.168.195
34.159.247.222
35.198.137.6
35.198.160.49
35.246.143.2
35.246.191.14
Step 2: Create and Activate a Data Filter
- Navigate to: Admin > Data Settings > Data Filters.
- Click on Create Filter.
- Select Internal Traffic.
- Choose a name for the filter, e.g., Exclude Cookiebot.
- For Filter Operation, select Exclude.
- Under Parameter Value, enter:
Cookiebot_traffic
. Ensure this value matches the traffic_type value from Step 1. - Set the Filter Status to Active.
- Click Create in the top-right corner.
Option 2: Exclude Cookiebot’s User Agent
Since IP addresses can change frequently, requiring constant monitoring and updates, Option 1 may not always be the most practical solution. A more reliable method is to exclude Cookiebot using its User Agent. Here’s how you can do this:
Step 1: Retrieve the User Agent Value in a GTM Variable
- Open Google Tag Manager.
- Go to Variables.
- Create a new User-Defined Variable.
- Select Variable Type: Custom JavaScript.
- Name the variable, e.g.,
CJS – navigator.userAgent
. - Enter the following code:
function () {return navigator.userAgent;}
- Save the variable.
Step 2: Adjust Tag Triggers
The goal is to add a new trigger to configuration tags where you want to exclude the Cookiebot crawler. Focus on tags with triggers related to page views, as the Cookiebot crawler does not execute events or actions other than loading pages.
Example: Adjust the “All Pages” Trigger to Exclude Cookiebot
If you’re using the All Pages trigger for something like loading Google Analytics, follow these steps:
- Go to the Triggers tab in GTM.
- Create a new trigger.
- Name the trigger, e.g.,
All Pages – Exclude Cookiebot
. - Select Trigger Type: Page View.
- Choose This trigger fires on some page views.
- On the left, select the variable you created in Step 1 (CJS – navigator.userAgent).
- Choose the condition Contains (default in GTM).
- Enter the value:
ookiebot
(without quotation marks, and without “C” or “c”, to avoid issues with case sensitivity). - Save the trigger and assign it to the relevant tag.
- Remove the current (All Pages) trigger from the tag.
Cookiebot’s User Agent typically looks like this:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko; compatible; Cookiebot/1.0; +http://cookiebot.com/) Chrome/X.X.X.X Safari/537.36
Final steps:
- Double-check your changes.
- Publish your updated GTM container.
If you’re unsure about these steps, consult someone familiar with Google Tag Manager. For assistance with configuring Cookiebot or reviewing your setup, feel free to reach out.
Disclaimer:
I’m sharing all of this information for free and this content is not sponsored. As an analytics nerd I’ve helped many companies to implement consent mode with different CMP’s such as Complianz, Cookiefirst, Cookiecode, Iubenda & more. However, my favorite CMP is Cookiebot by Usercentrics.
Therefore, I’ve signed up as a Cookiebot partner and I can give you a 20% lifetime discount on your subscription. I’ll have to invite you manually, so contact me if you want help and would like the discount.
If you want to support my content and don’t need the discount, when you click this affiliate link and sign up I’ll get a small affiliate fee. Thanks for reading this far, hope the content is helpful and if there’s anything I can help with: let me know!