Adam Brzostek
Reading time: 5:00

Mapping a custom subdomain to your tagging server in Google Cloud Platform (Cloud Run)

Mapping a subdomain to your tagging server takes server-side tagging a step further and brings extra benefits in the form of a first-party context, which means more secure and, above all, longer-lasting cookies. As a result, your data will be more accurate and your ads will target users more precisely, which should translate into savings in your ad accounts.

You may also want to read our other articles on server-side tracking:

For setting up the tagging server itself, I think Google's guide is good enough: https://developers.google.com/tag-platform/tag-manager/server-side/cloud-run-setup-guide?hl=pl&provisioning=manual . Mapping a subdomain the way Google recommends is much harder, though, which is why I wrote this article.

Introduction

When you set up a tagging server in Google Cloud Platform using Cloud Run, it gets its own default domain, created for this purpose by Google, where it is hosted.
This domain is the endpoint that receives all the requests (e.g. Google Analytics 4 events) you want to handle with server-side tagging.
The domain name combines your own tagging server name, a string of digits, the region where you set up the server and the fixed "run.app" part, for example:
https://server-side-tagging-1015978308997.us-central1.run.app
or
https://test-732008615078.europe-central2.run.app

integracja subdoemeny schema

Tagging on the default domain will still work correctly, but you only get the extra benefits described in the first paragraph once you map your own custom domain to the server.

integracja subdomeny schema

How to map your own domain to the tagging server

In October 2024, Google changed the process of mapping a subdomain to Cloud Run, and it is now much more complicated than before. The documentation isn't very clear here, so let's go through the whole process together, step by step.

According to Google's recommendation, the best way to map your own domain to the server is to set up a load balancer.

To do that, select Network services → Load balancing from the menu

konfiguracja load balancer menu

Keep in mind that the Compute Engine API must be enabled in your project

compute engine api enablement

Load balancer configuration

Once that's done, click the Create load balancer button

konfiguracja systemu równoważenia obciążenia start

We'll go through the most general, default configuration, which should work for most server-side tagging use cases.

In the first step, leave the default option selected: Application Load Balancer (HTTP/HTTPS)

konfiguracja systemu równoważenia obciążenia krok 1

In the next step, also leave Public facing unchanged

konfiguracja systemu równoważenia obciążenia krok 2

The next step stays unchanged too: Best for global workloads

konfiguracja systemu równoważenia obciążenia krok 3

In step four, again change nothing and keep Global external Application Load Balancer

konfiguracja systemu równoważenia obciążenia krok 4

To finish this stage, click the Configure button

konfiguracja systemu równoważenia obciążenia krok 5

Frontend configuration

So far it's been very simple, but now it gets a bit harder.

First, enter a name for the load balancer and a name for the frontend.

Then select the HTTPS protocol

You need to create a new static IP address

konfiguracja adresu IP krok 1

Just give it a name and click Reserve

konfiguracja adresu IP krok 2

The next setting is the certificate, which you need to create

konfiguracja certyfikatu SSL krok 1

Again, enter a name and select Create Google-managed certificate.

Here you also need to enter the domain you want to map, then finish by clicking Create.

konfiguracja certyfikatu SSL krok 2

Before moving on to the backend configuration, also check the option to enable HTTP to HTTPS redirect.

konfiguracja frontend podsumowanie

Confirm with the Done button and move on to the backend configuration

Backend configuration

Start this stage by selecting Create a backend service

konfiguracja backendu krok 1

Enter a name for the backend and select Serverless network endpoint group as the type.

konfiguracja backendu krok 2

In the Backends section, we'll create such a group.

konfiguracja backendu krok 3

As several times before, enter a name. Then choose a region. It's best to pick the same region where you created your tagging server, i.e. your Cloud Run instance.

Set the group type to Cloud Run and select the server you want to map from the drop-down list.

Click Create.

konfiguracja backendu krok 4

Then click Create in the backend service configuration window as well

We won't change the routing rules, so you can go to the last part of the process and create the load balancer.

load balancer confirmation

Creating your own subdomain

The load balancer is now configured, but it stays inactive until you create the domain you want to map.

When creating the domain, you need to add a DNS A record pointing to the right IP address.

To find this IP address, open your load balancer. You'll find it in the Frontend section.

ip adress for subdomain creation

Now create the domain whose name you entered when configuring the certificate, with a DNS A record pointing to that IP address.

It's best to pass this to your company's network administrator, unless you have access to the hosting control panel yourself.

The load balancer becomes active once the certificate is active. This can take up to several hours after you create the domain and add the DNS record.

You can check the certificate status under Security → Certificate Manager

certifcate manger menu

For this, the Certificate Manager API must be enabled in your project.

certificate manager API

You'll find your certificate on the Classic certificates tab

ssl certificate menu

At first, its status will probably look like this:

inactive ssl certiface

After a few hours, it should change to:

active ssl certificate

Adding the subdomain to the GTM container

The last and easiest step is adding the subdomain to the GTM container.

To do this, open Container Settings in your server-side container and click Add URL. Then enter your subdomain and click Save in the top right corner.

server gtm container settings

From now on, you can send all your GA4 tags to your own domain. You do this by changing the value of the server_container_url parameter (in my case, in the configuration settings variable)

If you're not sure how to map your own subdomain based on this article, get in touch.

I also encourage you to read the other articles in our server-side tagging series and to sign up for our newsletter to stay up to date.

Related articles

Get in touch

Characters left:
2000