A new way to set up a custom domain in server GTM

Updated May 19, 2026 comments

How to configure the same origin custom domain in sGTM

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

Want to join the server side?

Try for free

Was this article helpful?

Comments

Recommended for you

News

WhatsApp Conversion API

Learn how to implement WhatsApp Conversion API to optimize Click to Message ad campaigns. Integrate data from multiple sources for better campaign insights.

Sep 26, 2025

Turn better tracking into better marketing performance

Try for free