/Documentation

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.

How to add a custom domain in the Stape admin

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:

CDN toggle
  • 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.
Own CDN selected

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:

"How to connect" options
  • 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.

Automatic connection via Entri
  • Manually

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

Manual connection selected

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

You must create one CNAME record if you do not use Stape Global CDN and two records if you use Stape Global CDN.

1. Log in to your domain name service and create a new DNS record for the subdomain you want to use. To do it, click three dots and choose Configure DNS next to your domain name on the account home page.

Configure DNS

2. Click Add record.

"Add record" button

3. Go back to your Stape account and input the record you see in the account. Make sure that the Proxy status is turned off.

CNAME records in the Stape admin

We use Stape Global CDN, so we create two CNAME records:

CNAME record
Additional CNAME record (for the Stape Global CDN option)
Adding a custom subdomain with A and AAAA records
Please note that A/AAAA records are incompatible with enabled CDN.

1. If you need to verify your custom subdomain using A and AAAA records, add the custom subdomain to the container and make sure that the CDN toggle is switched off.

Click Advanced settings and tick the Use A records instead of CNAME records box. You will see DNS records that you should add inside your Stape container. The DNS records you should configure vary depending on the server location.

"Use A records instead of CNAME records" checkbox

2. Log in to your DNS account and add the records you see in your Stape account. On the account home page, next to your domain name, click three dots and choose Configure DNS.

Configure DNS

3. Click Add record.

"Add record" button

 4. Then, create the records you see in your Stape account. Make sure that the Proxy status is turned off.

Take the values for your DNS records from the Stape account:

A/AAAA records in the Stape admin

As a result, you will get two DNS records:

A record
AAAA record

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.

"Verify" button

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.

Status "Ready" in the Stape admin

Step 6. Add tagging server URL and update your website script

Go to your Google Tag Manager server containerAdminContainer Settings → change Tagging server URL to your subdomain.

Server container URL in GTM

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.

Custom Loader power-up interface

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. 

Configuring a custom domain with adding own CDN

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

Adding DNS records in Cloudflare

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.

Enter the DNS records from Stape
DNS records in Stape

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.

Verify the custom domain

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.

Wait for Stape to finish verifying your custom domain

5. Next, return to Cloudflare and click Rules → click OverviewCreate ruleConfiguration Rules.

Create a Rule under 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.
Fill in the required information

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

Add full SSL

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

Create a Request Header Transform 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.
Fill in the required information

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.

Configuring the Modify request headers section

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

Create a cache 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.
Fill in the required information

13. Scroll down to Cache eligibility and select Bypass cache

Then click Deploy.

Scroll down to Cache eligibility and select Bypass cache

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.

Comments

Can’t find what you are looking for?