GTM Server-Side Tracking: Advanced Analytics Capabilities

10/11/202313 min read


In today's digital world, tracking user interactions and capturing valuable data has become of utmost importance for businesses. Google Tag Manager (GTM) has been a popular tool for implementing tracking codes on websites, enabling efficient data collection for analytics platforms like Google Analytics, Adobe Analytics etc. To meet these challenges, GTM server-side tracking has come up as a powerful tool, which offers enhanced control, flexibility, and privacy compliance. In this article, we will learn the concept of GTM server-side tracking, why it's needed, and the advantages it offers when compared to traditional client-side tracking.

What is GTM Server-Side Tracking?

GTM server-side tracking is an innovative application of Google Tag Manager that transfers a portion or all tracking procedures from the client-side browser to a server. Instead of immediately activating tracking tags within the user's browser, GTM server-side transmits data to the server, where it can be analyzed, adjusted, or forwarded to third-party platforms. This configuration utilizes a server to oversee and distribute tags, optimizing tracking efficiency and unleashing a variety of advantages.

The Importance of GTM Server-Side Tracking:

  1. Improved Performance: By transferring tracking processes to a server, GTM server-side tracking offers a significant enhancement in website performance. Client-side tracking may encounter delays or errors due to various factors such as sluggish connections, ad blockers, or conflicts with JavaScript. Server-side tracking resolves these issues, ensuring quicker and more dependable data collection.

  2. Privacy Regulation Compliance: With the rise of regulations like the General Data Protection Regulation (GDPR) and the California Consumer Privacy Act (CCPA), safeguarding user data and ensuring privacy compliance have become crucial priorities. GTM server-side tracking provides greater control over data flow and aids in complying with data protection regulations by minimizing data exposure within the client-side environment.

Advantages of Implementing GTM Server-Side Tracking:

  1. Data Accuracy: Client-side tracking is vulnerable to various factors that can compromise the accuracy of collected data, such as browser extensions, script blockers, or interruptions in network connectivity. GTM server-side tracking addresses these issues by managing data collection and processing on the server, minimizing the risk of data loss or inconsistencies.

  2. Flexibility: GTM server-side tracking offers greater flexibility in managing and customizing tracking implementation. It enables server-side modifications to the collected data before transmitting it to analytics or marketing platforms. This flexibility empowers businesses to transform and enrich data, conduct advanced data processing, or seamlessly integrate with other backend systems.

  3. Reduced Dependence on JavaScript: Client-side tracking heavily relies on JavaScript, which can result in tracking failures when JavaScript is disabled or encounters errors. GTM server-side tracking reduces the dependency on JavaScript, making tracking more robust and reliable across a broader range of user environments.

  4. Resilience to Ad Blockers: Ad blockers have become prevalent, presenting challenges for businesses that rely solely on client-side tracking. GTM server-side tracking circumvents ad blockers, ensuring uninterrupted data collection and preserving accurate analytics insights.

  5. Reduced dependence on Third-Party Cookies: In the context of analytics tracking, first-party cookies are utilized to gather data about user interactions within a specific website. These cookies store information like page views, time spent on the site, and actions taken, allowing analytics tools to create detailed user profiles and understand site performance. Since first-party cookies originate from the same domain, they are generally less restricted by privacy measures like Intelligent Tracking Prevention (ITP) and offer more accurate and reliable tracking within a single site.

    While, third-party cookies are from domains other than the one a user is currently on. They are often used by advertising networks and tracking platforms to monitor user activity across multiple websites, enabling targeted advertising and user profiling. However, due to growing privacy concerns, many browsers, like Safari and Firefox, restrict or block third-party cookies, which can impact the accuracy of cross-site analytics tracking.

    Server-side tracking through Google Tag Manager (GTM) emerges as a solution to address tracking challenges posed by Intelligent Tracking Prevention (ITP) in browsers like Safari, where third-party cookie usage is limited.

    Unlike traditional client-side tracking, server-side tracking shifts tracking logic from the browser to the server. This shift yields several benefits: reduced reliance on third-party cookies, operation within a first-party context for improved tracking accuracy, greater control over data collection and processing, enhanced privacy compliance, flexibility in adapting to evolving browser privacy mechanisms, and better management of cross-domain tracking complexities.

To sum up, GTM server-side tracking has emerged as a compelling remedy for surpassing the constraints of conventional client-side tracking. Its heightened performance, adherence to data privacy regulations, enhanced data precision, flexibility, decreased dependency on JavaScript and Third-Party Cookies, and resilience against ad blockers make it a compelling choice for businesses aiming to harness advanced analytical capabilities.

How to Set up Server-Side Tracking

Step 1: Create a New Container

To begin, create a new GTM container and select the server option.

Select automatically provision tagging server. It is important to note that automatically provisioned tagging server is nothing but a Google Cloud Platform (GCP) tagging server. Initially, we will be using the default server URL provided to do the basic setup and test it. Later in the article, you will be taken through steps on how to scale that up for production environment in which you can use either a custom GCP tagging server or use your own custom server.

Step 2: Create a Billing Account

Set up a billing account within GTM to handle the costs associated with server-side implementation. This account will be linked to the GCP/custom server you create later. Since we will be using the automatically provided tagging server initially to test the set up, it will incur no charges.

Enter your personal details and Card information to complete the billing setup.

Step 3: Create a Tagging Server

Once you complete the billing setup, wait for a few minutes while the server is being created. Once created, you will receive a Google Cloud Platform project ID and the default server address.

Step 4: Open the Google Cloud Platform Project

Open the Google Cloud Platform Project Use the arrow next to the Google Cloud Platform project ID to access the project dashboard, where you can view error reports and billing details related to the server container.

Step 5: Configure Clients

The term "clients" refers to the different entities, platforms, or vendors that send tracking requests to your server. These clients could include analytics tools, advertising networks, or any other services requiring tracking data.

In “workspace”, select "Clients" to set up trigger events for the container. You will notice that a GA4 client is already present, open the same.

The priority determines the order in which clients are executed. The first client that matches the incoming http request becomes the active client for that request. Ensure that the activation path is set to the default GA4 path, including "/g/collect" in the Hits.

Step 6: Setup Tags

Create a new tag. Fill in the measurement ID and enable Google Signals if required. Google Signals if enabled will collect visitation information about the users who are signed into their google accounts and have consented to this association for the purpose of ads personalization. You can choose to redact visitor IP addresses based on your preferences. The event name will be a variable corresponding to the event received from the web container.

Step 7: Configure Triggers

Create custom triggers to control when the tag fires. Select the desired events and set the condition to match the client name with "GA4" (or the name you assigned to the client).

To setup the trigger, select “+” and then click on custom under trigger configuration

Use the below condition
Client Name equals GA4(since, currently our client is saved as GA4 this might be different if you have used some other client name)

Once done the tag will look something like this

Now every time the GA4 client receives any GA4 http request information, the above tag that we set up for GA4 on the server container will fire.

Step 8: Configure Web Container

Open the web container in a separate tab and navigate to the GA4 Configuration Tag. Check the "Send to server container" option and enter the server container URL obtained from the GTM ID in the server container. Save the configuration to ensure that all GA4 event information is sent to the server container.

Navigate to the GA4 Configuration Tag inside the web container and Check the box ‘Send to server container

Enter the server container URL(which can be found as mentioned earlier by clicking on the GTM ID on the server container)

Save this setup. Moving forward all GA4 event information will be sent to the server container.

Step 9: Selective Event Transport

Since server-side implementation incurs costs as per the number of events sent to the server for it to handle, you might want to send only some events to the server. If you want to send only specific events to the server container, uncheck the "Send to server container" option in the event tag configuration. Under "Fields to Set," add a new row with the field name as "transport_url" and the value as your server container URL. Repeat this step for each GA4 event tag you want to transport.

Step 10: Proxy GTM with Server Container

Now we need to set up a ‘Custom Client Template’ that will dictate how incoming http requests are processed before it is sent to a client in a GTM server container. This in a way connects the flow of http requests from your web container to the analytics server through the GTM server container.
Navigate to Templates, import the .tpl file(link) available on this link, and save it as the GTM Loader template. Then, create a new client under the server container settings and select the GTM Loader client.

Select ‘Import’ as shown in the screenshot below.

Once imported it will look something like this,

You will see the client name GTM Loader
Now save this Template after Agreeing to the Community Template Gallery Terms of Service

Now navigate back to the server container and select clients and add a new client

Under client configuration select the GTM Loader client we just added

Now you can change the request path as shown in the screenshot below to anything as per your requirement and then save this.

Step 11: Update GTM Scripts on the Website

Modify the GTM scripts on your website by replacing the source URL in the head code with your server container URL and request path. Similarly, update the GTM URL in the body code. These changes ensure that the website's events are transported to the server container for processing.

Navigate to your web container and click on the GTM ID towards the top right.

On the head part of the code we need to change src form'+i+dl’ to'+i+dl

Here is our server container URL and test_1 is the request path we set up inside the GTM Loader client

And in the Body code, just change to https://www.

Once again here is our server container URL

Step 12: Preview and Testing

Enable preview mode for both the web container and server container. Connect to your website through the web container's preview mode. Verify if the GA4 configuration tag fires on the server container's preview and check for incoming and outgoing requests.

While this is open, hit preview on the web container as well and connect to your website

On the web container’s preview, you will now see the GA4 configuration tag firing

Now navigate back to your server container and verify if any hits were received. Ideally, if everything is working fine, you’ll be able to see the GA4 Configuration tag fire on the server container’s preview and a page_view event will also be recorded.

Now click on page_view and then select requests

Here you can see the incoming request is to our server container URL and the outgoing request is from the server container to the analytics server.

Now if you have a custom event setup on the web container(any button click or form submission events) please trigger it. Let us consider a button click event here called ‘navigation_clicked’.

Go back to the server container and check if the custom event fired, select the same and check requests. You can again see the incoming and outgoing requests populating properly.

This concludes GTM server side setup for a test Environment. Follow the rest of the steps below to scale this up to a production ready environment.

Step 13: Production-Ready Setup

To scale up the server-side implementation for production, set up a custom GCP tagging server. Access the GCP Dashboard and navigate to Application Settings. Add a custom domain and complete the verification process. This custom domain will replace the default server container URL.

Note that the verification process may take up to 24 hours.

To create the custom domain URL, on the server container click on the GTM ID and click on the arrow next to Google Cloud Platform(GCP) Project ID to open your current project.

You will be redirected to the GCP Dashboard,

In the search field at the top, type App Engine and Select Application Settings


Enter the Domain Name and click on VERIFY

If your domain is not already verified via the Google Search console a new tab will open up to complete the verification. Here Under Domain, enter the Domain name and select CONTINUE

Once done, you will see something like this,

Now, we need to add the TXT Record from the pop-up in the above screenshot to the website DNS records. Please check with your website developer/DNS provider for more information on how to add DNS records for your website. Once this is done click on VERIFY.

The verification can take up to 24Hrs of time as mentioned earlier, post which you will get a custom domain to use instead of the default server container URL. The rest of the setup is the same as described above for the default server container URL.

Now comes the most important step to scale the server for production,
Navigate to your project on GCP and select the Activate Cloud Shell Option.

Give it a few minutes to load and the Shell will look something like this,

Confirm if the correct GCP project ID shows in yellow. If the project ID is incorrect you will need to navigate to the right one using the below command.

“Gcloud config set project [PROJECT ID]”

Once confirmed that the right project is selected, we will be entering the below command

bash -c "$(curl -fsSL"

Hit Enter and click on AUTHORIZE

Wait for a response from the Shell, and then Press Enter

Once you press Enter the shell will ask you a few questions about your preferences,

Press Enter for each of these if you don’t want to change any of them.

Now, we need to change the Deployment type from testing(default) to production and hit enter. You can leave Autoscaling as On as it is recommended.

Set the minimum number of servers as 3 (recommended), the maximum as 6 (recommended) and CPU target Utilization as 0.6 as shown below,

Hit Enter and confirm the settings.

Your server container is now production-ready and will incur charges according to the number of hits it receives. The billing controls are also present on the GCP Dashboard.


This approach allows you to have greater control over your analytics and marketing tags, leading to enhanced performance and flexibility. Remember to monitor costs and utilize billing controls available on the Google Cloud Platform Dashboard. With a production-ready setup, you can efficiently handle large-scale event tracking and leverage the power of GTM in your organization.