Configure a custom domain for your GTM Server-Side container on Google Cloud Platform: static IP, DNS, HTTPS certificate, load balancer and validation.

Illustration GTM Server-Side sur Google Cloud : un navigateur connecté par HTTPS à une infrastructure de serveurs cloud.

Setup your GCP and create a custom subdomain

  1. In your GTM Server, click on your “Google Cloud Platform Project ID” to access your GCP.

Ensure you are working in the correct GCP project linked to your billing account. Misconfigurations across multiple projects are common and lead to orphaned resources and billing issues.

Google Cloud project linked to the GTM server container

Set a secure and certified static IP address (The IP address of the Load Balancer Frontend) - The Load Balancer collects traffic from all the domains

Google Cloud static IP addresses
  1. Go to the GC IP addresses section
  2. Activate the Compute Engine API if needed
  3. Click on Reserve Static IP address
  4. Name the IP address, e.g. ‘ssgtm-ip’
  5. Go to the Network Service Tier and make sure ‘Premium’ is selected. Premium Network Tier is strongly recommended to ensure optimal latency and reliability for server-side tagging workloads.
  6. IP version should be IPv4
  7. Under Type settings, select ‘Global’ to make it available globally. The IP must be Global, not Regional. Global IPs are required for HTTPS global load balancers. Selecting a regional IP will cause the load balancer setup to fail.
  8. Click Reserve
Reserve a global static IPv4 address
  1. Copy your IP Address!

Map the IP Address in your DNS Manager

  1. Go to your DNS Manager provider
  2. Find your website and select Add a New Record
  3. Choose ‘A’ as the Record Type
  4. The name of the record will be the subdomain, e.g. sgtm, data, tracking, etc. I would recommend using non-related data as some ad blocker could use popular keywords to block tracking. I have chosen “data.”
  5. In the Value section, add the IP Address you copied
DNS A record for the tagging subdomain
  1. Save changes
  2. Verify that the address has been created correctly. DNS propagation may take several minutes to several hours depending on your provider. Until propagation is complete, SSL certificates and load balancer validation will not work.

Create an SSL (Secure Sockets Layer) certificate

Google-managed certificates are automatically renewed, which eliminates operational risk. Self-managed certificates are not recommended unless you have compliance constraints.

Google Cloud Certificate Manager
  1. Go to the Certificate Manager
  2. Activate the Certificate Manager API
  3. Go to Create an SSL certificate
  4. Name the certificate as ‘ssgtm-ssl-certificate’
  5. In Create mode, select Create Google-managed certificate
  6. Under domains, add the custom domain mapped in the DNS (like data.digitab.fr)
Create a Google-managed SSL certificate

New certificates typically require 10–30 minutes to be fully provisioned. During this time, HTTPS will fail—this is normal.

Create a Load Balancer Steps

The load balancer acts as a secure proxy between your users and your Cloud Run instance. It provides SSL termination, routing, and enhanced performance (HTTP/3/QUIC).

  1. Configure the Load Balancer
  2. The Load balancer handles the incoming traffic from your users' devices
  3. Go to Load Balancing
  4. Click on Create a load balancer
Create a global external application load balancer
  1. For Type of load balancer, select Application load balancer (HTTP/HTTPS)
  2. For Public-facing or internal, select Public-facing (external)
  3. For Global or single-region deployments, select Best for global workloads
  4. In Load balancer generation select, Global external application load balancer
  5. Click Configure to create, then
  6. Name the load balancer, e.g., ssgtm_load-balancer

Configure the Load Balancer Front End

The frontend configuration is highly sensitive: selecting the wrong certificate or IP address will cause persistent 404/502 errors.

  1. Go to Frontend configuration
  2. Name the load balancer’s front end, for example, ssgtm-lb-front-end
  3. Protocol must be HTTPS
  4. Keep IPv4
  5. From the drop-down, choose the IP address we created before
  6. Keep Port 443
  7. For the certificate, select the SSL certificate we created before, ‘ssgtm-ssl-certificate’
  8. Keep the SSL policy to the GCP default
  9. Keep the HTTP/3 (QUIC) negotiation to Automatic (default)
  10. Enable HTTP to HTTPS redirect
  11. Click Done

Configure the Load Balancer backend

  1. Go to backend configuration: here is where you configure the GTM server-side
  2. Click on the Backend services and backend buckets drop-down and select CREATE BACKEND SERVICE
  3. Name the Backend, e.g., ssgtm-lb-back-end
  4. In backend type, select Serverless network endpoint group
  5. Under New backend, select CREATE SERVERLESS NETWORK ENDPOINT GROUP

Then, in Create Serverless network endpoint group, name the setting adding in the label, the region where you set the Cloud Run or App Engine instance then name it ssgtm-network-endpoint-eu9. The Serverless NEG is mandatory for routing traffic from the load balancer to Cloud Run. The region of the NEG must match the region of your Cloud Run service.

  1. Next, select in Region, the region accordingly
  2. In the Serverless network endpoint group type select Cloud Run
  3. Then, in Services, select the Cloud Run or App Engine GTM Server-Side instance that you created
  4. Do not touch the other options
  5. Then click Create
  6. Next, continue the configuration menu, and disable Cloud CDN for now. Do not enable Cloud CDN. GTM Server-Side must not be cached, otherwise tracking payloads may not execute or may be served incorrectly.

You can enable Logging for the Load Balancer backend, but it will create more cost, it’s recommended leaving it for the moment,

  1. Under Security, set to set the drop down to none and revolve Cloud Armor as well
  2. Click create
  3. Then you will see an overview of the backend, click ok

Routing rules config

  1. Next go to Routing Rules,
  2. In Routing rules, select the Mode: Simple host and path rule
  3. Click on ADD HOST AND PATH RULE
  4. On Host add your mapped subdomain, on this tutorial was xxx.domain.com
  5. In path select /*
  6. In backend, select the backend we set
  7. Then go to Review and finalise
  8. Review the changes and then create the Load Balancer
  9. Test the setup
  10. Confirm the Load Balancer was set correctly
  11. Check the load balancer
  12. Check the Front end
  13. Check the backend
  14. Confirm the domain settings
  15. Check the Classic Certificate in Certificate Manager
  16. Verify the subdomain was mapped correctly

Add the Custom Subdomain into GTM Server Side settings

  1. Test the subdomain in tag assistant and page path /healthy

by accessing to mysubmain.mydomain.com/healthy, you should see “OK” in the page

  1. Go and check on https://toolbox.googleapps.com/apps/dig/
DNS lookup and subdomain verification
  1. Test the Load Balancer Monitoring feature to see the flow of traffic
  2. In GTM - container settings, add your server
GTM server container settings and server URL
  1. Click on Preview to test
GTM server container preview
Tag Assistant preview connection
  1. Then open a new tab and visit your subdomain, a HTTP ERROR 400 occurs
  2. Go back on the preview tab and check the line “/”, it validates the signal, you are done !
Server-side preview request validation