/Documentation

How to use same origin through Netlify

Updated Aug 12, 2026

Create an Edge Function file

// netlify/functions/metrics-proxy.js const TARGET_URL = "https://sgtm.example.com"; exports.handler = async (event, context) => { // Netlify often includes the client’s IP in x-nf-client-connection-ip const clientIp = event.headers["x-nf-client-connection-ip"] || "unknown"; // Build new headers object const newHeaders = { ...event.headers, "X-Forwarded-For": clientIp, "X-From-Cdn": "cf-stape", "CF-Connecting-Ip": clientIp, "Host": "sgtm.example.com", }; // Proxy the request to your target const response = await fetch(TARGET_URL, { method: event.httpMethod, headers: newHeaders, body: event.body, // pass the original request body }); // Build the response for Netlify const responseBody = await response.text(); return { statusCode: response.status, headers: Object.fromEntries(response.headers.entries()), body: responseBody, }; };

Testing 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?