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

Written by

Ira Holubovska

Updated May 15, 2026 comments

How to add a custom domain inside the server Google Tag Manager container

Using a subdomain

Types of custom domain config

Step 1. Add your custom domain

How to add a custom domain in the Stape admin

Step 2. Add CDN

CDN toggle

Step 3. Select the "How to connect" method

"How to connect" options
Automatic connection via Entri
Manual connection selected

Step 4. Add DNS records (for the manual connection method)

Adding a custom domain with a CNAME record
Adding a custom subdomain with A and AAAA records

Step 5. Verify your domain

"Verify" button
Status "Ready" in the Stape admin

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

Server container URL in GTM
Custom Loader
Tracking Score
Domain Settings
Score panel

Using the same origin

Note:

Note:

Step 1. Create a Cloudflare Worker

Start with Hello World!

Step 2. Name and deploy the worker

worker name

Step 3. Edit the worker code

export default { async fetch(request, env, ctx) { let { pathname, search, host } = new URL(request.url); pathname = pathname.replace('/metrics/', '/'); const domain = 'sst.shop.stapedesk.com'; let newRequest = new Request((`https://` + domain + pathname + search), request); newRequest.headers.set('Host', domain); return fetch(newRequest); }, };
Deploy and save your changes

Step 4. Add a route to the worker

Add a route to the worker

Step 5. Create a Configuration Rule

Create a Configuration Rule
Create rule

Step 6. Create a Request Header Transform Rule

Create a Request Header Transform Rule

Step 7. Update Custom Loader

Custom Loader

Step 8. Add the server container URL in the web and server GTM

server container URL in the web and server GTM
Server container URLs
Add client name
specify your Measurement ID
add the trigger for a tag

Testing your Same Origin setup

Testing your Same Origin setup
request from your website's real domain

Conclusion

Want to switch to the server side?

Try for free

Written by

Ira Holubovska

Content writer

Ira has 10+ years of digital marketing experience, with the last 5 focused on server-side tracking. She understands how and when it works across various digital marketing scenarios.

Was this article helpful?

Comments

Recommended for you

Turn better tracking into better marketing performance

Try for free