Skip to content

Consent in server GTM

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

This guide describes how to use consent signals coming from Usercentrics CMP (version 2 or later) and assumes you have:

  • A website using Usercentrics CMP already (go here if you don’t)
  • A working Usercentrics Server-Side Tagging sGTM container (go here if you don’t)

We want to have service-level consent status available in sGTM so that server-side tags can fire when there is consent for their associated service. To do that, 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. This way consent will be automatically available to the tagging server (if using a cookie) or can be added to the event data through web GTM. Let’s go through these steps.

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

  1. Download the file from this link.

  2. Go to Templates and under Client Templates click New. Import client template

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

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

The choice of whether to use a Javascript variable default or the cookie will depend on your preferences. The cookie option is simpler, as it is automatically transported with analytics requests, but you may want to avoid adding new cookies to your setup.

In order to actually activate this script for your container, you need to:

  1. Add the Client: select Clients, select New, and then UC Consent Manager Allowed DPS Client Add UC client

  2. Then select which transport method you prefer, click Save and then Submit, to publish the container Select transport method

Add the script to the page

Next, you need to 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 (of course changing it to your container’s custom domain):

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

If you’re not using the 1st-party cookie as your consent transport, you need to read it from the Javascript environment and pass it along with every request.

The consent data is actually being stored in 2 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 currently recommend reading from the window object.

In the web GTM container:

  1. Create a Javascript variable, with the following Global Variable Name value: window.ucConsentAllowedDpsString. Create a JS variable

  2. Go to the Google tag’s configuration, and under Event Parameters, add one named uc_consent_signals, and 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 services. Preview mode event parameter

Trigger server-side tags

Granular 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.

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 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 intend, and configure it as needed. As an example, we’ll use Google Analytics 4 which takes its configuration from the incoming event by default.

  4. Create a trigger condition for the tag that includes the name of the DPS (as defined in the CMP configuration). For this example, it’ll be Google Analytics 4, (include the trailing comma to ensure a match with the correct service from the list). There’s a second condition in this example, because we only want this tag to fire if the event comes from the GA4 client. Trigger configuration

Test the setup

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

  2. Reload the page. You should see the GA4 tag firing on the server container preview mode Test GA4 fired

  3. Now go back to the site, deny the Google Analytics 4 service in the CMP settings and save them Test deny services

  4. Reload the page. You should see that the GA4 service is not included in the list of services Test service not included

  5. You should also see that the GA4 tag did not fire Test GA4 did not fire

Use this for all your tags

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

For Google tags, you may opt to use consent mode as the trigger mechanism. You can read about it here.