Step 3. Add a custom domain
Updated May 13, 2026
Configuring a custom domain with Stape Global CDN
Step 1. Add your custom domain
Сhoose your container on Stape, scroll down, and click Add custom domain.

Add Subdomain name - it can be any name that works for you, just be sure to avoid using phrases specific to advertising or tracking: ad, gtm, stgm, tracking, analytics, metrics, stape, gtag, etc.
Step 2. Add CDN
A Content Delivery Network (CDN) distributes your website's assets across a global network of servers to reduce latency and improve load times for users in different locations. It is useful if your audience is geographically distributed or if you want to improve cookie tracking and data accuracy.
By default, the CDN is disabled, which means JavaScript files (like gtm.js, gtag.js, and analytics.js) are served directly from the server location where your sGTM container is hosted. Effectively, it bypasses both Stape Global CDN and Own CDN options and gives you a direct, unproxied connection between your site and the sGTM container.
| Important: please consider your country's privacy regulations before setting up a CDN. |
To enable the CDN, click the Add CDN toggle and select one of the following options:

- Stape Global CDN - loads scripts from a server closest to your website visitor's location, which reduces latency and improves page load times for geographically distributed audiences. We will use the Stape Global CDN in our setup. This feature is free and available for all Stape sGTM containers.
- Own CDN (incompatible with the Automatically (via Entri) connection option) - helps route sGTM custom domain and proxy sGTM traffic through the DNS provider of your website. In this case, the IP addresses of your website and the custom domain of the sGTM will match, and server-side cookies will be considered as first-party. As a result, it gives the ability to increase cookie duration.

Step 3. Select the "How to connect" method
Next, in the How to connect section, there are two ways of connecting a custom domain to your container:

- Automatically (via Entri)
The easiest way to connect domains. Log in with your DNS provider details via Entri, and give us one-time permission to connect your domain. That's it, you can proceed directly to Step 5 to verify your domain; no manual configuration is required.

- Manually
With this option, you have to add DNS records manually to your hosting provider to connect your subdomain to Stape.

After you add a custom subdomain to your container, you will see DNS records that should be created to verify the custom domain. The DNS record depends on the server location and the CDN option you choose. In the next step, we show how to add DNS records.
Step 4. Add DNS records (for the manual connection method)
By default, subdomain verification is performed with CNAME records, but you can verify your subdomain with A and AAAA records if you need to (usually in cases when you need to avoid adding duplicated records).
We will cover both options below with a step-by-step guide on how to create records using Cloudflare. But you can use any other provider.
Adding a custom domain with a CNAME record
Adding a custom subdomain with A and AAAA records
| Please note that A/AAAA records are incompatible with enabled CDN. |
Step 5. Verify your domain
Once you've entered the DNS records to your DNS provider, return to the Stape container page where you've been configuring the custom domain and click Verify.

Wait for Stape to finish verifying your custom domain (when the container status bar changes from Verifying to Ready). Usually, it takes 2-3 hours to verify the custom domain. For some DNS providers, verifying records might take up to 72 hours. We will email you once the custom domain is verified or any error is detected.
If you face any problems with domain verification, please follow our guide on troubleshooting a custom domain.

Step 6. Add tagging server URL and update your website script
Go to your Google Tag Manager server container → Admin → Container Settings → change Tagging server URL to your subdomain.

Update the script
If you use a custom domain, updating the Web GTM script on your website is highly recommended. This tweak will load gtm.js from your domain. To do so, replace the default domain googletagmanager.com with the custom domain you set up in the previous step.
Alternatively, you can automate this process with the Custom Loader power-up. Instead of manually editing the GTM script, Custom Loader generates a ready-to-use code snippet that loads GTM and GA4 scripts directly from your custom domain. This saves your time, makes your tracking scripts more resilient to ad blockers, and assures all cookies are treated as first-party.

Configuring a custom domain with adding own CDN
Own CDN allows serving custom domains (tagging server URL) from the same IP address as your website domain. It helps to set first-party cookies in browsers with ITP, like Safari and Firefox.

This example describes adding these records to Cloudflare DNS provider, but you can do the same with any provider you use.
1. Visit your Cloudflare profile → open the DNS tab in the side menu → open the Records screen → click Add record.

2. Enter the DNS records from Stape:
- Type - copy the TYPE parameter from Stape.
- Name - copy the HOST parameter from Stape.
- Target - copy the VALUE parameter from Stape.
- Proxy status - make sure to toggle this ON.
Click Save.


3. Once you’ve entered the DNS records to your DNS provider, return to the Stape container page where you’ve been configuring the custom domain and click Verify.

4. Wait for Stape to finish verifying your custom domain (when the container status bar changes from Verifying to Ready). Usually, it takes from 30 minutes to 2 hours, but in some cases it can take up to 72 hours.

5. Next, return to Cloudflare and click Rules → click Overview → Create rule → Configuration Rules.

6. Fill in the required information:
- Enter a descriptive rule name.
- Select Custom filter expression and enter:
- Field - hostname.
- Operator - contains.
- Value - paste the custom domain that you configured with Stape.

7. Scroll the page down to the SSL feature. Click Add next to it → select the Full option. Then click Deploy.

8. Next, go to the Rules → scroll to Request Header Transform Rules → click Create rule.

9. Fill in the required information:
- Enter a descriptive rule name.
- Select Custom filter expression and enter:
- Field - hostname.
- Operator - contains.
- Value - paste the custom domain that you configured with Stape.

10. Scroll down to the Modify request headers section. Select Set static, then enter:
- Header name: X-From-Cdn
- Value: cf-stape
Then click Deploy.

11. Next, go to Caching → click Cache Rules → click Create rule.

12. Fill in the required information:
- Enter a descriptive rule name.
- Select Custom filter expression and enter:
- Field - hostname.
- Operator - contains.
- Value - paste the custom domain that you configured with Stape.

13. Scroll down to Cache eligibility and select Bypass cache.
Then click Deploy.

Congratulations, now all your requests to and from sGTM will be proxied through Cloudflare. Please note that if you are using a Web Application Firewall, make sure that it does not block these requests.
Same origin custom domain for sGTM
Google has recently changed the preferred way of mapping a custom domain for the server Google Tag Manager container. Instead of using a subdomain (like sgtm.example.com) they encourage using the same origin (like example.com/sgtm).
With the same origin custom domain for sGTM, you will have the main benefit of server-side tagging - setting up first-party cookies. And with the tagging server using the same origin domain, you do not need to configure any additional settings to prolong cookies. However, mapping the same origin will be more complicated than configuring a subdomain.
Learn more about Same origin domain setup in our article.











Comments