Would you like to transfer to server-side tracking?
A website running client-side tracking relies on a container in the page to send measurement data to various collection servers. This container runs on the user’s browser or phone and has a direct connection to the mother server of your tracking tools.
Server-side tracking creates an interface between the two by enabling you to build your own tracking server. Google Tag Manager server-side tagging runs on the Google Cloud Platform and acts as a proxy between your client-side tracking and your marketing vendors.
From the browser, data gets sent to the GTM server-side instance and then forwarded to your tracking tools. This allows you to circumvent certain ad-blockers that hinder sending data to your tracking tools, and save data resources leading to an improved user experience.
In this guide, we’ll show you how to set up Google Tag Manager server-side tagging.
Here’s an overview of what we’ll cover:
- Server-Side Instance Setup
- Server-Side Preview Mode
- Sending Data to the Server-Side Instance
- Default Clients Event Data
- Sending Google Analytics 4 Tags
- What else can you do with Server-Side Tagging?
Server-Side Instance Setup
Let’s create a GTM server-side instance.
Log in to Google Tag Manager and set up a new account by clicking on Create Account.
Typically, you are setting up server-side tracking for a company, so let’s use their name for the account name.
Type the account name in the space provided.
You can also specify the country and optionally choose to share data anonymously.
Next, we need to provide the container name. I recommend putting your website domain in this field to help keep everything clean.
Fill in the container name, then click on Server for the target platform. Finally, click on Create.
We are then shown the terms of service agreement. Read through this article and ensure that you accept these terms.
Tick the check box below and click on Yes to accept.
Next, we’ll set up our tagging server. Here, we can automatically or manually provision the tagging server. If you already have your own server ready, you can follow the link for the user guide to manually set up the tagging server.
We’ll use the automatic provision option to deploy GTM server-side tagging through the Google Cloud Platform. Sign up and create a billing account here if you haven’t already.
Click on the Automatically provision tagging server button.
To create our tagging server, we’ll then select our billing account. If you already have a billing account in the Google Cloud Platform, it should be automatically selected.
Click on the Select billing account and create server button.
Creating a server may take a few minutes. Once created, we’ll see a window showing information such as the Google Cloud Platform project ID and the default URL. This is the server created where we can try out our GTM server-side instance.
Note that this is only a free sandbox for us to test our tags. If you want to run this on a live website, you will need to upgrade to a production version, which will cost you more.
Let’s click on Close.
Server-Side Preview Mode
If we look at our server-side instance, it looks like a typical Tag Manager workspace. The only difference is a new tab called Clients.
Clients are a new kind of entity for use in server containers. The client receives measurement data from a user’s device, turns it into events, routes data to be processed in the container, and packages up the results to send back to the requester.
Let’s verify if our server is reachable.
Click on our container ID.
Copy the default URL.
Next, click on Preview.
Instead of connecting GTM to our website, this puts our server-side instance into debug mode and opens a tab that looks similar to the Tag Assistant.
Opening our server (using the default URL we copied earlier) on another tab, we get the HTTP error 400.
It seems like our server cannot be reached, but if we look inside our server-side preview mode, there is a new entry.
Click on the new entry, then open the Request tab.
We can see that none of the clients claimed the request, and nothing has been returned. We do, however, have an incoming request, which is a slash. This is confirmation that our server is reachable.
Our GTM server-side instance is already set up. Therefore, we can go ahead and send data to our server-side instance, then relay this information to the Google Analytics 4 endpoint.
Sending data to the Server-Side Instance
Let’s go to our client-side Tag Manager account that is connected to our website.
Create a new tag by clicking on Tags → New.
We’ll be sending our data to Google Analytics 4, so we’ll need to make a Google Analytics configuration tag.
If you’re still using Universal Analytics, check out our GA4 migration guide.
Select Tag Configuration → Google Analytics: GA4 Configuration.
To configure our tag, we’ll need our website’s measurement ID on Google Analytics.
In your Google Analytics account, go to the admin section by clicking on settings. Go to Data Streams and select your domain.
Copy the measurement ID.
Paste this value back to Tag Manager. Check the Send to server container option, then paste our server container URL in the space provided.
Let’s attach a trigger by clicking on Triggering.
Choose the All Pages trigger.
Finally, ensure our server container URL does not end with a slash, apply a tag name, then click Save.
Now, let’s preview this tag by clicking on Preview.
Then, click on Connect.
Now, the data that should be sent to Google Analytics 4 will be relayed to our new server container URL.
If we check our server-side instance preview mode, we should have a page_view entry.
We can see details such as an incoming HTTP request and the client that claimed this request.
Default Client Event Data
Google Tag Manager already comes with a few clients included that we can see in the Clients tab in our server container.
We have Google Analytics 4, Google Analytics, Universal Analytics, and recently, we also have the Measurement Protocol included.
Every incoming request to our server container gets processed by the appropriate client into the right format we can later use in our tags.
The information that our client has passed is available to us in the server container under Event Data.
Our data is now being sent to our server container. Let’s create a tag to relay this information to the Google Analytics endpoint.
Sending Google Analytics 4 Tags
In our server container, go to Tags → New.
Although server-side tagging isn’t a new concept, this feature is relatively new to Google Tag Manager. Currently, there are a few server tags available, but they should increase in the future.
Let’s select Tag Configuration → Google Analytics: GA4.
Here, we can overwrite the request coming in. We can change the measurement ID or event name, for example. We only want to relay the request for now and see how GTM server-side tagging works, so leave these unchanged.
Click on Triggering.
Select the All Pages trigger, then click on Add.
Create a name for this tag, then click on Save.
While I named this tag “GA4 – Pageview”, it isn’t just for the page view entry. This tag relays any request that comes through the server-side instance since the All Pages trigger acts like an all-catch trigger.
Let’s try out the tag by clicking on Preview.
This opens another tab containing the debug information. Now, we need to send another request to our server-side instance, so that it gets relayed to Google Analytics.
Go to the client-side and refresh the website.
Head back to our server-side instance, click on page_view → Tags.
The tag seems to work properly. Let’s check our Google Analytics account to confirm.
Click on Configure → DebugView.
Great! We have the page view event that came in not from our website but was relayed through our server-side instance.
What else can you do with Server-Side Tagging?
There is still so much more that you can do with Google Tag Manager server-side tagging. For example, you can send data to the Meta Conversions API via Google Tag Manager server-side. You can also update your domain or upgrade your container.
Update your Domain
If you don’t want to use the AppSpot domain provided by Google, you can change this default domain inside your Cloud Console configurations.
We recommend that you use a subdomain of your website by following the steps for custom domain configurations provided by Google Developers. You can then change your server container URL by accessing your server-side container settings.
Go to Admin → Container Settings.
Simply replace the default domain URL with your created subdomain to finish upgrading your domain. However, since a subdomain is regarded as a separate website by Google, this option will incur additional costs.
Upgrade your Container
Another thing to consider is to upgrade the Google Cloud instance for your GTM server container to be production-ready. Upgrading the instance would mean that the cloud machine will have the capacity to handle more than you are testing.
If you decide to upgrade to the production version, submit a live version of your tags for both your server-side and client-side instances.
Go back to Tag Manager and click on Submit.
Finally, add a version name and click Publish.
That’s how you set up Google Tag Manager server-side tagging. With server-side tracking, you have increased control over your data.
Do you want to implement server-side tagging on a Shopify website? First, follow our guide on how to install Google Tag Manager and GA4 in Shopify.
What aspects of server-side tracking made you want to switch from client-side tracking? What improvements to GTM server-side tagging would you like to see? Let us know in the comments below!