GTM Server-Side: The Complete Guide

Updated: Saturday, January 20, 2024

The aim of this article is to give you all the keys you need to determine whether a server-side solution is right for your company, and also the steps you need to take to implement it.




You may be interested in a more specific guide:

What is Google Tag Manager client-side?

In its client-side version, Google Tag Manager collects data on your website and sends this data to marketing platforms such as Google Analytics, Google Ads or Facebook Ads via the browser.

flowchart LR
    subgraph Browser
        A[Your website]
        subgraph I[Google Tag Manager]
            F(GA4 tracking code)
            G(Google Ads tracking code)
            H(Facebook Pixel)
        end
    end
    C[Google Analytics 4 server]
    D[Facebook Ads server]
    E[Google Ads server]
    A --- I
    Browser -- google-analytics.com/collect --> C
    Browser -- www.facebook.com/tr --> D
    Browser -- googleadsservices.com/pagead/conversion/ --> E

The browser therefore sends requests directly to the marketing platforms you work with. Thanks to tracking codes, these platforms can deposit third-party cookies in the browser to identify the same visitor across several visits and/or link a visitor to an advertisement.

GTM Client-Side advantages

  1. relatively simple to set up (the biggest complexity lies in manipulating the Data Layer)
  2. the community has developed numerous tag and variable templates to make your life easier
  3. there are many tutorials on the Internet to help you out
  4. it’s what’s been done for a long time, so it’s easier to find these skills on the market (whether to recruit or outsource)
  5. Google Tag Manager Client-Side is completely free

GTM Client-Side drawbacks

  1. uses third-party cookies that will “normally” be removed in 2024
  2. tends to increase page load times, as you need to add a different tracking code for each marketing platform
  3. you have very little control over the data you send to marketing platforms (automatically collected user data, fingerprinting, etc.)
  4. requests sent to marketing platforms may be blocked by ad blockers

What is Google Tag Manager Server-Side?

Instead of sending requests to each server of the marketing platforms you use, you’ll only send requests to your own server. Your server will then communicate with the marketing platforms.

flowchart TD
    subgraph Browser
        A[Your website]
        subgraph I[GTM Client-Side]
            F(GA4 tracking code)
        end
    end
    subgraph J[Your server]
        subgraph K[GTM Server-Side]
            R[GA4 client]
            L[Google Ads tag]
            M[Facebook Ads tag]
            N[Google Analytics tag]
        end
    end
    R --> L
    R --> M
    R --> N
    Browser <-- HTTP --> J
    L -- googleadsservices.com --> O[Google Ads API]
    M -- graph.facebook.com --> P[Facebook Ads API]
    N -- google-analytics.com --> Q[Google Analytics API]

GTM Server-Side advantages

  1. reduces your website’s loading time (especially if you need to send data to many marketing platforms)
  2. gives you total control over what data is sent to marketing platforms, as your server acts as an intermediary (it dictates what data goes through and what doesn’t)
  3. fingerprinting becomes impossible with server-side tracking
  4. you’re less prone to ad blockers, as GTM and GA4 javascript libraries in particular can be downloaded from your server

GTM Server-Side drawbacks

  1. you have to pay to host your server in the cloud
  2. managing a server in the cloud requires additional skills (setup, monitoring, scaling, etc.)
  3. few tag templates are currently offered by the community

Client-Side VS Server-Side required skills


mindmap
  root[Client-Side vs Server-Side required skills]
    [Client-Side]
      :::blue
      (Javascript)
        (Variables)
        (Functions)
        (JSON)
      (Cookies)
      (CSS selectors)
      (DOM HTML)


    [Server-Side]
      (HTTP)
        (Requests and responses)
        (Cookies)
        (JSON)
        (Logs)
      (Cloud)
        (DNS)
        (Load balancing)
        (Resource monitoring)

Frequently Asked Questions


Will my Client-Side configuration be obsolete if I switch to server-side?

No. Your client-side implementation can be reduced to a single type of tag (e.g. GA4) that will send the data to your server, reducing your website’s loading time because you’ll have fewer tags. All your triggers will still be useful. If you’ve set up a Data Layer, this doesn’t have to go to waste either, the client container will keep on using it.

Do I have to change my tag implementation plan or measurement strategy if I switch to server-side?

You can update your client-side tag implementation plan if you remove some tags. You can also create a tag implementation plan for the server-side. On the other hand, the events you measure will remain the same. Moving to the server-side changes the way data is fed back to marketing platforms from a technical point of view, but in no way alters your measurement strategy.

Yes. GTM server-side is just a different technical implementation, but this doesn’t change the current legislation.

Create a server container in GTM with Cloud Run

Provisioning a new server container

In Google Tag Manager, create a new container and choose Server as the target platform.

Server container creation in GTM
Server container creation in GTM

Once you’ve created your container, Google Tag Manager will ask you how you’d like to configure your server. You can do this either automatically (this will set up a server for you in Google Cloud) or manually (this gives you the option of configuring your server yourself).

To make things easier, we’ll choose automatic provisioning.

Automatic provisioning of the tagging server
Automatic provisioning of the tagging server

At this stage, if you don’t have a billing account in Google Cloud, you’ll need to create one.



Once this is done, select your billing account and create your server.

Billing account selection
Billing account selection

Creating the server will take a few minutes…

Tagging server created
Tagging server created

Once the server has been created, two important pieces of information are displayed:

  1. The Google Cloud project in which your server is located
  2. The default URL for sending requests to the server

Linking your domain name will enable cookies to be deposited in a first-party context. This is one of the advantages of server-side tracking, so this step is important.

Go to your Google Cloud project then Cloud Run.



Select Cloud Run in Google Cloud Platform menu
Select Cloud Run in Google Cloud Platform menu

This brings you to the overview of your Cloud Run services.

Here you can see that there are two services:

  1. the tagging server
  2. the preview server

With this configuration, test requests will be sent to the preview server and real requests will be sent to the main tagging server.

To link your domain name, click on the main tagging server service:

Cloud Run services after automatic provisioning
Cloud Run services after automatic provisioning

Then, go to the Integrations tab.

Integrations tab in Cloud Run
Integrations tab in Cloud Run

Click on Add integration then select Custom domains.

Custom domains integration in Cloud Run
Custom domains integration in Cloud Run

Then enter your sub-domain and activate the necessary APIs.

Custom domain configuration in Cloud Run
Custom domain configuration in Cloud Run

Once the APIs have been activated, click on the SUBMIT button.



Add your DNS record

In the Custom domain integration you’ve just created, a window shows you how to configure your DNS record.

DNS record to configure
DNS record to configure

For my part, I’m going to do this configuration on Cloudflare but this depends on the DNS host you use.

DNS record configuration in Cloudflare
DNS record configuration in Cloudflare


Waiting for custom domain linking and SSL certificate generation
Waiting for custom domain linking and SSL certificate generation

Depending on your DNS host, the link of the domain name with your Cloud Run tagging server and the generation of the SSL certificate may take between 10 minutes and 24h.

Once this is complete, the integration status will change to Active.

Custom domain linked and SSL certificate activated
Custom domain linked and SSL certificate activated

Test the server with your domain name

Before testing your domain name, you’ll need to modify the server container configuration to indicate the new URL of your server.

To do this, go to Admin then Container settings. Here, change the server container URL.

Change server URL in GTM server container settings
Change server URL in GTM server container settings

Then, activate the preview mode in your GTM server container.

Preview mode activation button in server container
Preview mode activation button in server container

At the same time, enter your server’s domain name (in this case https://sst.data-marketing-school.com) in your browser. You should get a 400 HTTP error.

Test request to server
Test request to server

Even if you get an error at this stage, this means that the server has responded and is running. You can check this in GTM Server-Side’s preview mode.

Request received by the server
Request received by the server

Congratulations, you’ve completed your server’s Cloud configuration.

Enable logging



On Google Cloud, go to the Load balancing section and click on the backends tab. Here you should see your server.

Backends section in Load Balancing menu in Google Cloud Platform
Backends section in Load Balancing menu in Google Cloud Platform

Click on the backend service corresponding to your server, then on Edit.

Backend service editing
Backend service editing

Scroll down to the Daily section, then edit the settings as follows.

Logging configuration on the backend service
Logging configuration on the backend service

Then, click on the Update button.

Congratulations, you’ve activated logging.

Deploy Cloud Run server to production

Once you’re happy with your Server-Side configuration, you need to put your server into production before sending real traffic.

Go to the settings of your Cloud Run instance and scroll down to the Autoscaling section.

The default settings are as follows:

Autoscaling default settings
Autoscaling default settings

Google’s recommended settings for going live are between 2 and 10 instances. Cloud Run instances will be added or removed according to traffic load.

Autoscaling production settings
Autoscaling live settings

Then, click on Deploy.


Delegate cloud management

Here are 3 services that manage the entire infrastructure/cloud of your Server-Side implementation from A to Z: