How to add a custom domain to the Google Tag Manager Server container

Oct 6, 2020
Also available in

In this article, I will describe how to set up a custom subdomain within your Google Tag Manager server container. The main advantage of a custom subdomain inside the Google Tag Manager Server container is that it helps to bypass Intelligent Tracking Preventions, AdBlockers and increases cookie lifetime for users browsing in Safari. Pixels will be loaded from your subdomain and run as the first-party. 

Why Should You Use Custom Subdomain Inside Google Tag Manager Server Container?Copy link to this section

Google Tag Manager Server-side tagging allows moving out third-party tracking pixels off the website or app to the server-side environment.

Server-side tagging offers a few advantages over client-side tags:

  1. Faster performance: Fewer tags are running on your website or app. It means less code runs inside the browser, improving your website speed.
  2. More security: Data is better protected as it will be managed inside the server-side environment.

You have two option for tagging server URL:

  • use tagging URL that was created for you and is hosted on our domain (
  • create a custom subdomain.

We recommend setting up a custom subdomain since with the custom subdomain you’ll enjoy the following benefits:

  • Bypassing ITPs and AdBlockers;
  • Extended cookie lifetime.

Tracking prevention doesn’t affect requests from your own domain. Your website will bypass AdBlockers and ITPs, giving the full data about your website visitors and conversions.

How to add Custom Subdomain Inside Google Tag Manager Server Container?Copy link to this section

First of all, you need to create and set up the Google Tag Manager server container. If you don’t have a server container follow this instruction.

1. Log in to your stape account, choose a container, scroll down and click Add domain.

add custom domain

2. Navigate to your DNS provider; for instance:

  • GoDaddy
  • Google Domains
  • Hostgator
  • Hover
  • Namecheap
  • Squarespace
  • AWS
  • Cloudflare

3. The below example will show how to add DNS setting in Cloudflare. Login to your account -> click on your site’s domain -> Click DNS -> Add record

set DNS record custom subdomain server google tag manager

4. Add these setting:

Type: A

Name: ss (or any other subdomain you prefer)

IPv4 address: IP address depends on the location of the servers. You can find the custom domain IP address in your account. 

TTL: Auto

Proxy status: disable

Your settings should look like this:

set DNS record custom subdomain sGTM


Do not forget to add CNAME record if you enabled CDN for your container. You will find required CNAME records in the container settings.

5. Once you have done, click Save.

6. Go to your account and add a custom domain. It should consist of the name that you added to Cloudflare and your domain. Click Save. After adding the domain, it passes through the verification process. It can take up to 72 hours. Once the domain is verified, the status will be changed to “Verified”

You can force stape to verify domain by clicking "revalidate domain" button near in sGTM container setting 

revalidate domain

7. Once your GTM subdomain is added and verified, you should see the status Running.

set up subdomain stape

 8. Go back to the Google Tag Manager Server container -> Choose your server container -> Admin -> container settings -> paste tagging server URL.

set tagging server url in gtm

Updating the Web GTM script on your website is highly recommended if you use a custom domain. This tweak will make gtm.js load from your domain. To do so, replace the default domain with the custom domain you set up in the previous step. 

update google tag manager script stape

9. Inside the Web container, create a new tag of the tag Type Google Tag. Add your Google Tag ID.

In the section Configuration settings add the following parameters:

  • Name: server_container_url
  • Value: Enter the URL

Add trigger to GA4 tag. Normally it should trigger on all page views. 

set up Google Analytics 4 server-side 

You can also create a Google tag: Configuration settings variable that will predefine Google Tag settings if you need to use multiple Google Tags on your website and do not want to add settings for each of the tags manually.

These parameters can be, for example, a setting that defines whether you want to send a page view event every time a Google Tag triggers, set UTM parameters, client ID, etc. There is a list of standard Google Tags configuration parameters.    

10. To set up the GA4 event, go to the tags section and create a new tag with the tag type Google Analytics: GA4 Event. Add your GA4 ID and the event name; there is a list of standard event names

You can create a Google Tag: Event Settings variable that will help to share event parameters across several GA4 event tags or Google Tags. It can be, for example, user or product properties, and there is also a list of standard parameters for event settings. 

Google analytics 4 events settings 
google tag event settings variable

11. Open Google Tag Manager Server container -> click Client -> create GA4 client and save it -> go to Tags and set up GA4 tag. Remember that GA4 automatically sends not only pageview but some other events. Inside Event Name choose variable {{Event Name}}. -> add trigger Client Name equals GA4.

set up ga4 tag in the server container 
set up ga4 client in the server container 

12. Open the Server container preview mode and check that you see GA4 requests. Publish updated inside server and web Google Tag Manager containers. 

test ga4 trigger in the server container 

That’s it! Now your GTM server container runs from your subdomain.

Frequently Asked Questions:Copy link to this section

1. It's been more than 72 hours, but my domain still not verified. 

First of all we recommend using one of free online DNS checkers to verify if DNS settings are correct. Stape team uses this tool by Google. All you need to do is add your custom domain and verify that A and CNAME records (in case you've enabled Global CDN

check if DNS records are correct stape

You must have only one A record and one CNAME record (if you've enabled Global CDN). If there are multiple records please remove non-stop records and use another custom domain for stape.

2. I've checked my DNS settings, it's correct but domains is still not verified. 

If you've previously used the same subdomains for GCP ensure that you removed AAAA record. Also log in to your stape account, open sGTM container settings and click Revalidate Domain. 

In case all these did not help, contact support

revalidate domain

Got trouble with adding a custom domain?

All it takes is a few simple questions. Click Get help, fill up the form, and we will guide you.

Get help
Tagged with:gtm server

Relevant posts

Aug 20, 2021

Third-party cookies are about to expire. Will server-side tracking help?

By the end of 2024, Chrome and Chrome-based browsers will be done with third-party cookies. Safari and Firefox already implemented Intelligent Tracking Algorithms that can block trackers. That leads to the next point: digital advertising methods that rely on third-party cookies to target consumers might become ineffective or even stop working altogether. This change in how advertisers track users will hurt many publishers and ad networks that rely on these third-party companies to display ads and collect data from site visitors to understand their audience. In this blog post, I will explain what a third-party cookie is, why it matters, and how server-side tracking can help businesses transit to the world without third-party cookies.

Oct 8, 2021

How much does server GTM cost and why Stape is cheaper than Google Cloud’s App Engine

What cost can you expect for server Google Tag Manager hosted on Google Cloud? Is it a good idea to use a test environment on the productions site. Why stape’s hosting for server GTM is cheaper and how we secure our user’s data.

Feb 28, 2021

Google tag manager server-side: How to set up server Tag Manager, Universal Analytics, GA4, and Facebook conversion API

Server-side tagging has been one of the main trends in web analytics for the last couple of years. Ad blockers, Intelligent Tracking Protection, 3rd party cookie restrictions, regulations like GDPR made analytics and advertising companies start worrying about how and what information they collect about site visitors. Server-side tagging allows moving third-party tags off your site and into a cloud server. In this case, third-party pixels are loaded directly from the could server rather than your site. In this article, I will explain and demonstrate the basics of setting up Google Tag Manager server container, server Universal Analytics, GA4, and Facebook Conversion API.

Host your GTM server at Stape