#GTMTips: Map Multiple Domains to a Server-Side Tagging Endpoint

This article shows you how to map more than one custom domain to a single Google Tag Manager server-side tagging endpoint.

One of the biggest perks of working with server-side tagging is that you can establish a first-party context between the site sending the data and the server-side tagging endpoint itself.

This leads to many benefits, including improved control of the data streams, the possibility to set cookies that extend beyond ITP’s restrictions, and reduced stress on an already very likely overloaded Content Security Policy.

However, by default you only map a single custom domain to any given tagging server. This is because there is actually only one domain you can configure as the Tagging Server URL in the container admin.

In this article, I want to show you that even though it’s true that you can only configure one Tagging Server URL, this doesn’t mean that the endpoint won’t work with more than one domain!

Tip 124: Map multiple domains to a Server-side Tagging endpoint

For a domain to be in first-party context with some other domain, these two domains must share the top privately-controlled domain name.

Take www.simoahava.com and sgtm.simoahava.com. The highest possible domain name that I can privately control is simoahava.com (as I can’t buy .com). As this is shared by both domains, these are considered to be in first-party context.

So, when I created my server-side container, I configured it to use sgtm.simoahava.com as the domain name, after which any request sent to it from www.simoahava.com (or any other subdomain) would be considered to be a first-party request.

Now, what about when I want to use the same container to cater to requests from www.gtmtools.com?

If I send a request from www.gtmtools.com to sgtm.simoahava.com, the top privately-controlled domain name is not the same (simoahava.com vs. gtmtools.com). The request would work, and the server container could do stuff with it, but it would be a third-party request which has a significant impact on, for example, how cookies are processed.


Map additional custom domains to the endpoint

By going through the steps to map a custom domain again, and adding new domain mappings (using A/AAAA DNS records), the server-side tagging endpoint can be configured to respond from more than one domain.

In the screenshot above, I’ve mapped three different domains to the server-side endpoint. This means that without any further configuration, I can send requests to any one of those three domains, and the server-side endpoint will process them.

Preview mode requires some work

So what is the purpose of the Tagging Server URL setting?

The Tagging Server URL setting decides on which domain the Preview mode is opened when the Preview button is pressed in the GTM UI.

As I have sgtm.simoahava.com set as the Tagging Server URL, it means that whenever I click the Preview button, a new tab is opened with Preview mode loaded on sgtm.simoahava.com.

But how do I then go into Preview mode for any of the other custom domains?

You might have guessed it:

  1. Open the Preview mode for the Tagging Server URL by clicking the Preview button.
  2. Edit the URL and replace the Tagging Server URL domain with any of the other custom domains mapped to the service.

This will reload Preview mode, set the necessary first-party cookies, and open the Preview interface on the custom domain that you specified in the URL.


Mapping more than one custom domain makes a lot of sense if you have, for example, practically identical sites just served off a different TLD (e.g. country sites) or a different site altogether (e.g. brand sites).

The underlying server infrastructure stays the same – mapping custom domains doesn’t mean that additional servers are added to the setup or anything like that. They are just additional entryways to the server-side tagging endpoint.

Naturally, each additional site you set to collect data to the server-side tagging endpoint will place additional stress on the instances running in the stack as well as your monthly bill. You might also need to configure your Clients and tags to accommodate data coming from multiple different domains if, for example, they are designed to set cookies in the responses (the domain of the cookie needs to match the domain of the request origin).

But the crux of the matter is this: it’s possible to map multiple custom domains to a single server-side tagging endpoint, and it’s actually quite easy to do so!

Have you had a need to map more than one domain to a server-side tagging endpoint? If so, what were your experiences in doing so? Please let the readers know in the comments!