Server-side tracking with Google Tag Manager and Cloud run

Table of Contents

Server-side tracking has become one of the buzzwords these days, but it’s not all hype. It has the potential to help us regain some data quality lost due to ad-blocking technologies, regulations, and the need to adapt to a cookieless future.

Client-side tracking is not enough

We are so used to tracking on the browser that a concept like server-side tracking seems a bit strange to us. However, as we will see, the old approach has some severe limitations when you consider the current reality of digital analytics.

Collecting data and privacy concerns

On top of the list of problems is that how much data you can collect is becoming quite limited. Using GA4 requires explicit user consent. The issue is that only a part of traffic will grant consent. This depends on factors like location and your particular industry.

On top of the list of concerns is that how much data you can collect is becoming more and more limited. Using GA4 requires explicit user consent. The issue is that only a part of traffic will grant consent. This depends on factors like location and your particular industry. 

You can use a tool that doesn’t need users consent with the right configuration like Matomo, Piwik pro to name but a few. These tools have a lot of similarities with Google Analytics 4 (GA4) and are easier to use. One common approach for EU based businesses, is to use Matomo/Piwik pro along with GA4. This will help you see the missing data in GA4 in the second tool without giving up the powerful features of GA4.

Ad and tracking blocking technologies

Even if you get a user’s consent, you still have to face another challenge: ad blockers.

We are entering a new era of web tracking. Third-party cookies are disappearing. Most browsers are blocking them, even if the user doesn’t use an ad blocker. It’s not only about ads; using analytics and the good old pixel in the standard way will soon become obsolete.

Can server-side tracking save the day?

As with any new technology, people are hailing server-side tracking as THE solution. But like any technology, it has its limitations.

It will help you prevent some data loss due to ad blockers, but you still won’t be able to track users who do not consent. You will need other technologies like consent mode (not available for server-side GTM yet). 

What server-side tracking can’t do

Get you 100% of data

Server-side tracking won’t get you all the data. It’s a common misconception by people who are new to this discussion. The main advantages are reducing the impact of ad blockers and tracking in a first party context. 

You won’t need the user’s consent anymore

you will need consent, unless you are using:

Configure SSGTM with Cloud run

The process may seem intimidating at first, but it’s pretty straightforward. You only require a server and a Google Tag Manager (GTM) container.

Create a server-side container

You need to create a Google Tag Manager Server-side container. Go to the admin section and create a new server container.

server_container_gtm

The server container is quite similar to the web version, we have:

  • Familiar sections like tags, triggers, and variables.
  • Server-side specific sections like clients and transformations.

server side gtm dashboard

Once you hit save, a pop-up will appear in your new container. Click on “automatically provision tag server”.

Automatically provision server side

GTM will create a new server in the US-Central 1 region. Don’t worry, if your customers are in the EU, you can change the region later on.

Create a billing account

add bliing account

Follow the steps and once you are done, you can select the billing account you added from the dropdown and click to provision the server.

server side billing account

In a few moments, you will see a new screen with your server’s details.

Server side intaance information

Upgrade the number of instances

When you browse to Cloud Run in your GCP account, you will find two types of servers:

  • Server-side-tagging: The main server that receives data.
  • Server-side-tagging-preview: As the name indicates, this server will preview requests by the server.

Services in cloud run

Open server-side-tagging

Click on “EDIT & DEPLOY NEW REVISION” then scroll to the bottom.

Edit and deploy new revision

You will notice that our deployment is running on 0 to 1 server. This is fine for testing purposes, but the number of servers will likely not be enough for a production environment. Having only one server can cause abrupt pauses when there are traffic spikes.

Autoscaling instances

We need some margin of safety by upgrading to at least 2 and up to 10 instances. This will guarantee smooth functioning of your deployment. Even if traffic spikes, the new setup can handle it.

Change server location (optional)

Changing your server’s location is a good idea, especially for businesses based in the EU. It brings your server closer to your customers and helps to stay in line with GDPR, for example.

Copy the Server-side-tagging-preview

Copy preview service

The simplest way to do this is by selecting and copying the server-side-tagging-preview.
Once copied, you can change the region to europe-west2 (England), for example.

The only things you need to change are:

  • The name of the new server:server-side-tagging-eu, for example.

change location

  • Check the option “Allow unauthenticated invocations”.

Allow unauthenticated invocations

Copy server-side-tagging

Copy tagging server

We will do the same thing for the server-side-tagging. Ensure that you change the “PREVIEW_SERVER_URL” to point to the new preview server.

Add server tagging URL

Make sure to change the name and check “Allow unauthenticated invocations.”  You can delete the old setup and keep only EU services.

Create a custom domain

One of the main benefits of server-side GTM is to load cookies from a first-party context. The default domain is still considered as third party. We need to fix this by creating your own subdomain.

Create a new integration

Go to your tagging server and browse to the integration

all custom domain 1

Select “Custom domains, Google Cloud Load Balancing”. Here, you need to add your custom domain, for example: ssgtm.hamzaelkharraz.com.

add custom domain 2

Next, enable all APIs and click on submit.

This process may take up to 24 hours or more.

Add DNS records to your hosting provider.


Once the DNS records are available, browse to your hosting provider and add the A record. If you don’t have access, you can ask your developer to do this for you.

Configure CDN record

Configure GTM web tags

By this time, we are ready to link our web container with the new server-side domain. We do this by adding the server URL to the configuration tag.

Google Tag Manager URL server

Final words

Server-side tracking will play a major role in a world that doesn’t rely on third-party cookies. It is a bit weird at first, but one could argue that learning is a must. More and more vendors like Facebook are pushing towards this approach.

Of course, there are many ways to set up server-side tagging. This approach is quite complicated for those new to GCP. Feel free to reach out if you are having issues with setting up your SSGTM.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Go Further