Server-Side GTM + Consent Mode Setup with Complianz

This guide provides step-by-step instructions for setting up Google Tag Manager (GTM) with Server-Side tagging and Consent Mode using the Complianz plugin. It’s designed to simplify the process and guide the integration, especially when dealing with server-side implementations.

Step 1: Configure GTM through Complianz Plugin

  1. Access the Complianz Wizard:
    • Go to Wizard → Consent → Statistics
    • Choose “Yes, and Google Tag Manager fires this script”
 

  1. Disable Other GTM Plugins:
    • If you have other GTM plugins active, disable them to avoid conflicts.
    • Remove any custom GTM scripts from your website that were manually added.
  1. Verify Configuration:
    • Ensure that the statistics configuration in Complianz is set up correctly. The configuration should look similar to this screenshot:
 

  1. Install Complianz Template in GTM:
    • Go to the Template Gallery in your Google Tag Manager dashboard.
    • Search for and install the Complianz template.
 

Step 2: Server-Side GTM Configuration

❗️ For users with a Server-Side GTM setup, additional configuration is required.

  1. Modify the GTM URL:
    • Server-Side GTM implementations require replacing the standard GTM URL (googletagmanager.com) with your custom server GTM URL (e.g., gtm.yourdomain.nl).
  1. Override the “GTM Consent Mode Template script”:
    • The Complianz plugin allows overriding the default GTM Consent Mode template script. Specifically, this template refers to the file located at wp-content/themes/custom-theme/complianz-gdpr-premium/templates/statistics/google-tag-manager-consent-mode-template.js, which includes a customizable Google Tag Manager snippet for server-side tagging.
    • Locate the directory of your current WordPress theme:
      • For Complianz Premium with a theme named “custom-theme” the folder path will be:
wp-content/themes/custom-theme/complianz-gdpr-premium/templates/statistics/
    • Create a new file named google-tag-manager-consent-mode-template.js in this directory.
    • Insert the adjusted GTM + Consent Mode script from this gist.
    • Modify the GTM URL on line 6 of the script to your own Server-Side GTM URL (e.g., gtm.yourdomain.nl). Locate the following line within the script:
				
					(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
        new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    
    // *** Modify the following line with your Server-Side GTM URL ***
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    // ************************************************************

})(window,document,'script','dataLayer','{gtm_code}');

// The code continues...
...
				
			

Step 3: Multisite Considerations (If Applicable)

For WordPress Multisite installations, if a single theme is used across all subsites:

  1. Shared Consent Mode Template:
    • The same Consent Mode template file will be used across all subsites.
    • The {gtm_code} in the GTM script will be replaced with the GTM code configured in the Wizard for each subsite.
  1. Custom Logic for Server-Side GTM URLs:
    • If different Server-Side GTM URLs are required for different subsites, you can define a list of GTM container IDs in the template file.
    • Associate each GTM container ID with the appropriate Server-Side GTM URL.
    • Update the GTM source URL in the script accordingly.

If you encounter any issues, please carefully review the steps outlined above and follow them closely.

Join 1M+ users and install The Privacy Suite for WordPress locally, automated or fully customized, and access our awesome support if you need any help!

Complianz has received its Google CMP Certification to conform to requirements for publishers using Google advertising products.