Skip to content

GTM Server Side

This is the most complex implementation, and server container it's possible to implement it in multiple ways, such as Google Cloud, Amazon Web Service, Stape, Taggrs or similars.

The guide will focus on easiest and most common solutions as Stape or Taggrs, if you want to deploy Server Side with Google Cloud or AWS solution, please refer to the official documentation, or contact us for custom integrations.

Before start, you have to know that Server Side integration requires 2 GTM containers.

The Client or Web container acts as a first-party container provided by the server-side container. Its role is to receive events from your website or application and forward them to the server-side container for further processing.

The Server container is deployed in a third-party service (Stape, Taggrs, Google Cloud, etc.). It collects events from the client-side container, processes the data to match the expected schemas of tracking platforms (e.g., GA4, Google Ads, Bing, Facebook), and sends the processed data to the final endpoints.

In summary, you need complete the next steps

  1. Create GTM Server Side Container
  2. Deploy Server Side Container with your preferred solution
  3. Create GTM Client Side Container
  4. Download and import Workspaces on both containers
  5. Setup container settings
  6. Edit the Constants Variables in Server-Side Workspace
  7. Configure Container Settings to allow Tag Assistant

Create GTM Server Side Container

Server Container Settings

Follow this steps to deploy Stape or Taggrs

  1. In your GTM account, click on logo to access the Account page.
  2. Click on Accounts tab.
  3. Click on Options button.
  4. Click on Create Container button.

  1. Set your Container name.
  2. Select Server as the container type.
  3. Click on Create to create the container.

  1. Click on Cross to discard this step.

  1. Click on Admin tab.
  2. Click on Container Settings.

  1. Click on Set up your tagging server.

  1. Select Manually provision tagging server.
  2. Copy the Container Config string (required to set up the Server container on external services like Stape or Taggrs).
Server container URLs

This step is required to enable Tag Assistant in your server container.

  1. Click on Add URL.
  2. Set the URL to your server container (e.g., https://subdomain.yourdomain.com).

Deploy Server Side Container

Choose your preferred solution to deploy the server-side container and follow the corresponding instructions.

Stape

Stape is a server-side container hosting solution that simplifies the process of deploying and managing server-side containers. It provides a user-friendly interface and various features to enhance performance and security.

Create a Stape Account

If you do not have one, create a Stape account here. Once you have an account, follow the steps below to set up your server-side container.

Create a Stape Server Side Container

  1. In your Stape dashboard, click sGTM
  2. click on Create sGTM container

  1. Enter a container name (it doesn't have to match your GTM container name).
  2. Paste the Container Config you copied from GTM.
  3. Select a server location that's geographically close to your target audience.
  4. Click on Create Container.

  1. Choose a Stape plan (they offer a free tier to start).
  2. Click on Continue to proceed with the setup.
Setup Custom Domain

  1. Click Add custom domain.
  2. Enter a Domain name (e.g., metrics.yourdomain.com).
  3. Enable Add CDN to improve the loading times
  4. Select Stape CDN or use your Own CDN
  5. Select Manually to get DNS Instructions
  6. Click Next to set up the custom domain.

Info

  • To prevent detection by advanced ad blockers that often target subdomains like gtm, stape, taggrs, or similars, consider using different, less predictable subdomains for your integration.
  • The Domain name is the value to set up on module configuration GA4 tab, Server Container URL input field.

  1. Set up the CNAME or A records and add it to your domain DNS settings.
  2. Click Verify in Stape to confirm the DNS are correctly deployed.

Info

The Verification process may take a few minutes, depending on your DNS provider.

Configure Stape Power-Ups

It is essential to set up at least the Custom Loader and GEO Headers

Custom Loader

Custom loader is a Stape feature that allows you to load the GTM container in a more efficient way, improving performance and reducing the impact of ad blockers.

  1. In your Stape dashboard, click over sGTM and select your GTM container.
  2. Click on Power-Ups tab.
  3. On Custom Loader panel click on Use.

  1. Enable the feature.
  2. Click on Save Changes.

  1. Select the Domain ( previously configured ).
  2. Add your Web GTM ID.
  3. Enable Ga4 ad block bypass.
  4. For Same Origin Path, check Stape documentation or contact support.
  5. Select Other Platform
  6. Set Data Layer Variable Name, leave it empty for default value.
  7. Select Generate with CDN
  8. Disable Use original GTM code.
  9. Click on Generate.
  10. Check the generated code and follow the next instructions.
Module Configuration From Stape Code

Warning

The stape code below is only an example do not use it, you must create your own code in your stape account.

Example Stape Script With Custom Loader
    <!-- Google Tag Manager -->
    <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);
            j.async=true;
            j.src="https://load.metricstp.reactioncode.com/2rqhgioesoz.js?"+i;
            f.parentNode.insertBefore(j,f);
        })(window,document,'script','dataLayer','cnfl0o=aWQ9R1RNLVBLQjNIUTM%3D&apiKey=fbf0cf8');
    </script>

    <!-- End Google Tag Manager -->
Next parameters are located in module configuration Tag Manager tab.

  • Script URL: https://load.metricstp.reactioncode.com/2rqhgioesoz.js
  • Query ID Parameter: cnfl0o
  • Override Tracking ID: aWQ9R1RNLVBLQjNIUTM%3D&apiKey=fbf0cf8
GEO Headers

GEO Headers is a Stape feature that allows you to send the user's location to the server-side container, improving data accuracy and reducing the impact of ad blockers.

  1. In your Stape dashboard, click over sGTM and select your GTM container.
  2. Click on Power-Ups tab.
  3. On GEO Headers panel click on Use.

  1. Enable the feature.
  2. Click on Save Changes.

Taggrs

Taggrs is a server-side solution that allows you to deploy your GTM container in a more efficient way, improving performance and reducing the impact of ad blockers.

Create a Taggrs Account

If you do not have one, create a Taggrs account here. Once you have an account, follow the steps below to set up your server-side container.

Create a Taggrs Server Side Container

  1. At left menu, click on Containers
  2. Click on + Add container
  3. Set your Company Name
  4. Set your website index URL (e.g., https://yourdomain.com)
  5. Select the nearest Server location
  6. Click on Continue to proceed with the setup.

  1. Set your Container configuration code
  2. Set a subdomain for your server-side container (e.g., metrics.yourdomain.com)
  3. Be sure that Use a TAGGRS subdomain instead is disabled
  4. Click on Create container to create the container.

Info

  • To prevent detection by advanced ad blockers that often target subdomains like gtm, stape, taggrs, or similars, consider using different, less predictable subdomains for your integration.
  • The Domain name is the value to set up on module configuration GA4 tab, Server Container URL input field.

Setup Custom Domain

  1. Set up the A records and add it to your domain DNS settings.
  2. Click on Validate container and wait for confirmation.

Info

The Verification process may take a few minutes, depending on your DNS provider.

Optimize your container

Taggrs provides features to load the GTM container in a more efficient way.

Enhanced Tracking Script

Improves performance and reduce the impact of ad blockers.

  1. In your container panel, select Get Started panel.
  2. Select Optimize section.
  3. Click on Enhanced Tracking Script.

  1. Click on Advanced configuration.
  2. Enable option Extend cookies.
  3. Enable option Anti ad blocker.
  4. Set up your GTM Web container ID.
  5. Copy the Head code and paste it on any editor to fetch the configuration.
  6. You can skip the Body code as it is not needed for this module.
Module Configuration From Taggrs Code

Warning

The Taggrs code below is only an example do not use it, you must create your own code in your Taggrs account.

Example Taggrs Script With Enhanced Tracking Script
    <!-- Server Side Tracking by Taggrs.io -->
     <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='https://metricstgrs.reactioncode.com/POpiGHQ1la.js?tg='+i+dl;
            f.parentNode.insertBefore(j,f);
        })(window,document,'script','dataLayer','PKB3HQ3');
    </script> 
    <!-- End Server Side Tracking by Taggrs.io -->

Next parameters are located in module configuration Tag Manager tab.

  • Script URL: https://metricstgrs.reactioncode.com/POpiGHQ1la.js
  • Query ID Parameter: tg
  • Override Tracking ID: PKB3HQ3
Data Enricher

Data Enricher is a Taggrs feature that allows you to add additional data to your tracking events, such as user agent, IP address, and other information that can help you better understand your users.

  1. In your Taggrs dashboard, click over Get Started.
  2. Select Enrich tab.
  3. Click on Data Enricher feature.

  1. Active the Data Enricher feature.
  2. Verify that all Items are enabled.

Create GTM Client Side (WEB) Container

Download Server Side Workspaces

Download the Full Server Side Workspace Configurations (05/06/2025) to import it in your GTM Workspace. only since module version 3.4 and 4.4

Tip

Unzip the downloaded file to obtain the JSON files and be able to import it into Google Tag Manager

Import Workspaces

The workspaces provided in the zip are divided by containers, and server side folder has divided by tracking platforms. To ensure optimal performance and avoid unnecessary configurations, just import only the workspaces for the platforms you need:

Web Container

The web container is the standard GTM container that you are already familiar with. It is used to manage and deploy tags on your website. The web container is responsible for collecting data from your website and sending it to the server-side container for processing.

When you unzip the importation file you will find a folder called Client. This folder contains the web container workspace for server side. Just import it and overwrite the existing workspace. This workspace is configured to work with the server-side container and includes all the necessary tags, triggers, and variables to send data to the server-side container.

  1. In your GTM web container, click on Admin.
  2. Click on Import Container

  1. Select the configuration file to import.
  2. Select the workspace.
  3. Select Overwrite to remove old tags and clean up your current workspace.
  4. Click on Confirm.

1. Click on Submit to publish all changes.

Server Container

The server container is the GTM container that is deployed on a third-party service (Stape, Taggrs, Google Cloud, etc.). It is responsible for processing the data collected from the web container and sending it to the final endpoints (e.g., GA4, Google Ads, Bing, Facebook).

Import GTM Client

When you unzip the importation file you will find a folder called Server. Among the files you will find the tracking platforms and the essential one named gtm_server_script_provider, this includes the gtm client, required to provide the script to the web container.

  1. In your GTM server container, click on Admin.
  2. Click on Import Container

  1. Select the gtm_server_script_provider_... file to import.
  2. Select the workspace.
  3. Select Overwrite to remove old tags and clean up your current workspace.
  4. Click on Confirm.
Import Required Platforms

The server container is divided by tracking platforms. To ensure optimal performance and avoid unnecessary configurations, just import only the workspaces for the platforms you need:

  1. In your GTM server container, click on Admin.
  2. Click on Import Container

  1. Select the configuration file to import
  2. Select the workspace
  3. Select Merge to combine your current workspace
  4. Select Overwrite conflicting tags, triggers and variables
  5. Click on Confirm

  1. Click on Submit to publish all changes.

Configure Constants

It is essential to configure the constants variables in the server-side workspace to be able to provide the GTM script from your server and send the data through the API platforms.

Provide the GTM script

The GTM - SCRIPT CLIENT requires to define the allowed containers to be able to provide the GTM script from your server. This is essential to ensure that the GTM script is only provided to the allowed containers and to prevent any unauthorized access.

  1. In your GTM server-side workspace, click on Variables.
  2. On search input, type constant to filter the variables.
  3. Click on GTM - Web Container ID to edit the variable.

  1. Click on Variable Configuration panel.
  2. In the Value field, paste the GTM Web container ID.
  3. Click on Save to save the changes.

Configure API keys

For security reasons the module does not send the API keys in dataLayer, therefore depending on the tracking platform, it is essential to configure the constants variables in the server-side workspace to be able to send the data through the API platforms.

Platforms that requires to configure constants variables:

  • Criteo, see instructions to get the API key here.
  • Facebook, see instructions to get the API key here.
  • Pinterest, see instructions to get the API key here.
  • TikTok, see instructions to get the API key here.
  • Twitter, see instructions to get the API key here.

Once you have an API key, you can configure the constants variables in the server-side workspace. To do this, follow these steps:

  1. In your GTM server-side workspace, click on Variables.
  2. On search input, type constant to filter the variables.
  3. Click on API - YOUR_PLATFORM / Access Token to edit the variable.

  1. Click on Variable Configuration panel.
  2. In the Value field, paste the API key you obtained from the platform.
  3. Click on Save to save the changes.