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
- Access the Complianz Wizard:
- Go to Wizard → Consent → Statistics
- Choose “Yes, and Google Tag Manager fires this script”
- 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.
- Verify Configuration:
- Ensure that the statistics configuration in Complianz is set up correctly. The configuration should look similar to this screenshot:
- 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.
- 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
).
- Server-Side GTM implementations require replacing the standard GTM URL (
- 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:
- 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/
- 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:
- Create a new file named
(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...
...
For guidance on configuring CoMo2, please refer to this helpful procedure: Simplified Guide to Google Consent Mode V2.
Step 3: Multisite Considerations (If Applicable)
For WordPress Multisite installations, if a single theme is used across all subsites:
- 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.
- 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.
Important Notes
Ensure that GTM4WP integration is set to Off in Complianz if using Consent Mode.
Set the Container Code to Off in GTM4WP.
If you encounter any issues, please carefully review the steps outlined above and follow them closely.