/Documentation

How to use same origin through Cloudflare

Updated Oct 1, 2026

Before you begin

Setup guide

Step 1. Create a Cloudflare Worker

Create a Cloudflare Worker

Step 2. Name and deploy the worker

Name and deploy the worker

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.stapedesk.com'; let newRequest = new Request((`https://` + domain + pathname + search), request); newRequest.headers.set('Host', domain); return fetch(newRequest); }, };
Edit the worker code

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

Request Header Transform Rule:

Step 7. Update Custom Loader

Update 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

Was this article helpful?

Comments

Can’t find what you are looking for?