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.
In this article, I’ll show you how to map multiple custom domains to your Google Cloud Project application. I’ll also show you how to configure the container to support previewing all these different domains.
The Simmer Newsletter
Follow this link to subscribe to the Simmer Newsletter! Stay up-to-date with the latest content from Simo Ahava and the Simmer online course platform.
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.
Solution?
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.
Configure the container and enter Preview mode
In the Google Tag Manager Server Container Settings (under Admin), you then need to add these domains to the Server container URLs list:
Once a domain is in this list, you can enter Preview mode for that domain.
To enter Preview mode, go back to the regular workspace view in GTM, and click the little selector next to the Preview button.
In the overlay that appears, click the domain name you want to enable Preview mode for.
After doing this, whenever you click the Preview button, it will open Preview mode for whichever domain is currently selected behind the domain selector.
Verify it all works by clicking the Preview button and double-checking it opens in the correct origin.
Summary
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!