/Documentation

How to use same origin through Deno Deploy

Updated Aug 12, 2026

Deploy proxy code

constORIGIN_PATH = "/metrics"; constGTM_URL = "https://sgtm.example.com"; Deno.serve(async(request, connInfo) => { consturl =newURL(request.url); if(url.pathname.startsWith(ORIGIN_PATH)) { constnewHeaders =newHeaders(request.headers); newHeaders.set("X-Forwarded-For", connInfo.remoteAddr.hostname); newHeaders.set("X-From-Cdn", "cf-stape"); newHeaders.set("CF-Connecting-Ip", connInfo.remoteAddr.hostname); newHeaders.set("HOST", "sgtm.example.com"); returnfetch(GTM_URL, { method: request.method, headers: newHeaders, body: request.body, }); } return newResponse(null, { status: 404 }); });

Using Deno Deploy's web interface​

Using Deno Deploy's web interface​
Paste the contents of the proxy script 

Using Deno's runtime CLI

deno init proxy-project-folder
deno deploy

Test your Same Origin setup

Test GA4 tag
Adding the same-origin path to container settings
Preview opened at the new path
Incoming page_view request from your real domain

Was this article helpful?

Comments

Can’t find what you are looking for?