Skip to content

Use consent signals in your server-side container

While you can use your server-side tagging container with any CMP, we have made it very easy to integrate with Cookiebot and Usercentrics Web CMP.

This guide describes how to use consent signals coming from either of these CMPs and assumes you have:

  • A website using Cookiebot or Usercentrics Web CMP (version 2 or later), or some other CMP using Google Consent Mode.
  • A working Google Tag Manager (sGTM) container backed by Usercentrics. Read the Gertting started page if you need to set it up.

Jump to the step-by-step instructions below for your CMP:

Cookiebot and Usercentrics Web CMP

Follow these instructions to easily integrate consent status with Server Google Tag Manager (sGTM) for either Cookiebot or Usercentrics Web CMP.

We will deploy a new script to the page that tracks the consent status, stores it in a local JavaScript variable and (optionally) in a first-party cookie. With this setup, consent will either be automatically available to the tagging server (if using a cookie) or can be added to the event data through web GTM. The following steps will guide you through the process.

The script to track and store service consent status is delivered to the page through a custom client template.

Follow these steps to set that up:

  1. Download the template file from here.

  2. Go to Templates and under Client Templates click New.

    Client Templates - New

  3. From the top right menu, select the Import option. Then select the client template file, click Save and close the template editor.

    Import client template

The script that keeps track of consented service or category status stores data in the window, the Data Layer and (optionally) in a first-party cookie.

The choice between using a JavaScript variable default or a cookie will depend on your preferences. Using a cookie is simpler because it is automatically included with analytics requests, but you may prefer to avoid adding new cookies to your setup.

To activate this script for your container, follow these steps:

  1. Add the client. To do so, select Clients, select New, and then Usercentrics Cookiebot consent signals client.

  2. Select the CMP you're using on your website (Cookiebot or Usercentrics Web CMP).

  3. Then select which Delivery method you prefer, click Save, and then Submit to publish the container.

Note

If the domain the container will be associated with is a multi-label eTLD (e.g. co.uk and com.au), you should select the Event Data method. There's currently an issue in the script that prevents it from handling those domains as intended.

Add the script to the page

Next, add the consent signals script to the page. You should place it in the page's <head> section, above the CMP script.

The script tag to use is the following (remember to change it to your container's custom domain):

<script src="https://demo.example.com/uc-consent-signals.js"></script>

If you're not using the first-party cookie as your consent transport, you should read the consent signals from the JavaScript environment and pass them along with every event.

The consent data is stored in two locations: the window object and the data layer. You may read the data from either, but be mindful that depending on the timing of the client-side event trigger, it may not be available in the data layer yet. To get started, we recommend reading from the window object.

In the web GTM container:

  1. Create a JavaScript variable named uc_consent_signals. In the Global Variable Name field, set it to:

    • Cookiebot: window.cbAllowedCategories

    • Usercentrics Web CMP: window.ucConsentAllowedDpsString

  2. Go to the Google tag's configuration, and under Event Parameters, add a parameter named uc_consent_signals. For its value select the variable created in the previous step (in this example, we also named it uc_consent_signals).

    Set event parameter

  3. This will automatically add this parameter to all events using this Google tag configuration. To test it's working as expected, go to Preview Mode and inspect the Page View event. You should see the parameter containing a list of consented categories (with Cookiebot) or services (with Usercentrics Web CMP).

    • Cookiebot example

      Preview mode event parameter

    • Usercentrics example

      Preview mode event parameter

Trigger server-side tags

Consent signals are now reaching the server-side container, either through a cookie or event data. We will now use them to decide whether a server-side tag should be triggered or not.

Setup for Cookiebot

  1. Create a variable. Select the type based on your transport option:

    1. If using a cookie, select a Cookie Value variable, reading from the cbAllowedCategories cookie name.

    2. If using event data, select an Event Data variable, with the key value being the same event parameter name used before (in our example, it was uc_consent_signals).

      Create server-side event data variable

  2. Test if the variable is working by using the server container’s Preview Mode and then reloading the website. Select the page_view event and then the variables section. You should now see the variable there.

  3. Add the server-side tag you want, and configure it as needed. As an example, we’ll use the Google Ads Conversion Tracking Tag that triggers on a custom newsletter_lead event.

  4. Create an exception trigger condition for the tag that includes the name of the category (one of necessary, preferences, statistics or marketing). For this example, it’ll be marketing . This means that the tag will not trigger if this condition is verified.

  5. Save the tag and test the setup.

Test the setup (Cookiebot)

To test the setup, follow these steps:

  1. Launch the server's Preview mode, go to your website and accept all services in the CMP banner.

  2. Generate your test event condition (loading the page or something else). You can use any tag or event to test your triggers. In this example, we will use the same Google Ads and custom event from before (but you could use the Google Analytics 4 tag with the page_view event for easier testing). You should see the tag firing on the server container preview mode.

  3. Now go back to the site, deny the Marketing category in the CMP settings and save.

  4. Repeat your testing conditions that trigger your testing event (e.g. page_view or in our example here, newsletter_lead). You should see that marketing is not included in the list of categories.

  5. You should also see that the tag did not fire because the Exception trigger condition was verified.

Use this for all your tags

Now you can use this approach to trigger any server-side tag with consent using Cookiebot.

Setup for Usercentrics Web CMP

In the server GTM container:

  1. Create a variable. Select the type based on your transport option:

    1. If using a cookie, select a Cookie Value variable, reading from the ucConsentAllowedDps cookie name.

      Create server-side cookie variable

    2. If using event data, select an Event Data variable, with the key value being the same event parameter name used before (in our example, it was uc_consent_signals).

      Create server-side event data variable

  2. Test if the variable is working by using the server container’s Preview Mode and then reloading the website. Select the page_view event and then the variables section. You should now see the variable there.

    Test the server-side variable

  3. Add the server-side tag you want, and configure it as needed. As an example, we’ll use the Google Ads Conversion Tracking Tag that triggers on a custom newsletter_lead event.

  4. Create an exception trigger condition for the tag that includes the name of the Data Processing Service (DPS) as defined in the CMP configuration. For this example, it’ll be Google Ads . This means that the tag will not trigger if this condition is verified.

  5. Save the tag and test the setup.

Test the setup (Usercentrics)

To test the setup, follow these steps:

  1. Launch the server’s Preview mode, go to your website and accept all services in the CMP banner.

  2. Generate your test event condition (loading the page or something else). You can use any tag or event to test your triggers. In this example, we will use the same Google Ads tag and newsletter_lead custom event from before (but you could use the Google Analytics 4 tag with the page_view event for easier testing). You should see the tag firing on the server container preview mode.

  3. Now go back to the site, deny the Google Ads service in the CMP settings and save them.

  4. Repeat your testing conditions that trigger your testing event (e.g. page_view or in our example here, newsletter_lead). You should see that Google Ads is not included in the list of consented services.

  5. You should also see that the Google Ads tag did not fire.

Use this for all your tags

Now you can use this approach to trigger any server-side tag with consent using Usercentrics Web CMP.

If you are using other Consent Management Platforms we recommend relying on Google Consent Mode signals to determine when server-side tags should be triggered.

Here's the high-level view of how it works:

  • The Google Analytics 4 data stream carries consent signals on every request.

  • We will read these signals into variables in the server-side container.

  • We will use the values in those variables to determine if a tag should be triggered or not.

Let's walk through each step:

  1. Go to the Variables section and under User-Defined Variables, click New.

    Create new variable

  2. Select the Event Data variable type and

  3. In the Key Path field, type x-ga-gcs (you can also name it the same), and save it.

    x-ga-gcs variable

  4. Go to the Triggers section, click New and select the Custom trigger type.

  5. Set it to fire on Some Events. Select the x-ga-gcs variable, choose the “matches RegEx” condition and in the value set it to G1\d0.

  6. Add a name for the trigger (e.g. “Events without Analytics consent”) and save it.

    No analytics consent trigger

  7. Still in the Triggers section, create another trigger by clicking New and selecting the Custom trigger type.

  8. Set it to fire on Some Events.
    Once again, select the x-ga-gcs variable, choose the “matches RegEx” condition and in the value set it to G10\d.

  9. Add a name for the trigger (e.g. “Events without Ads consent”) and save it.

    No ads consent trigger

  10. Now, in any server-side tag (from Google or other vendors), create an Exception trigger. Depending on the purpose of the tag, select either the “without Analytics consent” or “without Ads consent” triggers as the exception. This ensures the tag will not trigger if the required consent is missing. Exception trigger

Use this for all your tags

Now you can use this approach to trigger any server-side tag with other CMPs (or when you just want to use Google Consent Mode signals).