Same origin SSGTM proxying questions

Hi there, I was excited to see this post as it’s something I’ve been looking to test myself:

However, it seems like the blog post ends before explaining some key things. For example, some questions I ran into:

  1. How do you preview / test the server-side container now? I am not able to preview it using in GTM Server container when I set that as the debugging URL. I get an error, “Your Session has Expired”

  2. I currently doing this via CloudFlare method and I am wondering about CF proxying. In my worker I use my custom domain; which is proxied through CloudFlare. I feel like maybe I should remove the proxy for that is pointing to Stape as the request is essentially proxied already through

Any other guides / tips would be great!

1 Like
  1. For preview you need to add to settings of server GTM container and use it for run preview.
    “Your Session has Expired” – If it happens all the time, it’s probably a problem with your server settings or DNS settings.

  2. Yes, you can keep only the option you will actually use

Hi Alex, I actually found that Google Server-side on same origin requires you pass the Host header, and in the article on the code sample for CloudFlare Workers does not include it (the NGINX sample does). I had to add that to fix it. Not having it also created data issues in GA4. My updated code was:

export default {
  async fetch(request, env, ctx) {
	let url = new URL(request.url);
	let newPathname = url.pathname.replace('/data/', '/');
	let newUrl = `${newPathname}${}`;
	let newRequest = new Request(newUrl, request);
	newRequest.headers.set('Host', '');
	return fetch(newRequest);
1 Like