Custom domain in server GTM


Could you please give us some more info about this

I am not using Cloudflare and I am not sure how to use nginx. Should I just show that article to the hosting provider and they will do the rest?
There is smth thai I can do without reaching hosting?


Hey Alin,

Essentially this approach wouldn’t work without a load balancer, so if you’re hosting provider is willing to implement that for you - by all means do reach out.

Hey, @Dan

Ok, I will reach them.
I am not sure what means - load balancer - but I suppose that they will know. :slight_smile:

On Stape side - do I have to do something? To change or add something in my account?


I did this myself using a proxy and a cache buster so we just accept the request on our server and proxy it over. I set up the caching flags so that it gets cached in the CloudFlare cache tier and also the browser (hence the cache buster query parameter we use when we roll out new GTM client side changes). That way it comes from our domain and we have better control over it. Since it’s cached, there is not a lot of load on our servers.

Hello, @bossman2024,

Not sure how your answer help me since I dont use CloudFlare as stated in my first comment.

You don’t need CloudFlare to implement the same thing. Just build a small proxy in your own web site to proxy the script files (that the request and pass it onto Google). But that will only work if you can develop your own web site code. If not you may want to use the Stape power up to proxy it as the have that feature also.

Our site is written in C# so I could provide a sample of what we did if that would help.

The original topic is about proxying all traffic, not just files or gtm.js/gtag.js. So you need to proxy all requests that use sGTM so it is described on article either ngnix or CloudFlare.
This is necessary to ensure that the IP address of the sGTM and the site are not different and that Safari sets genuine first party cookies.
@Alin_Tatarca If you don’t have this options you can use just Cookie Keeper power-up to restore cookies

Ahh yes, you are correct. Since we use Cloudflare setting up the proxy via Cloudflare was very easy. Honestly I would highly recommend setting up a Cloudflare config for your domain as it was a lot easier than messing with Google load balancing.

Hey, @Alex!

The hosting company said that my website is on a shared server, so the “nginx thing” is available only for dedicated servers. (I cannot double check this, so if they are lying, I am lying too)
So I am a kinda stucked. Not sure what to do next.

The article is meant only for those who have a dedicated server?



Hey man, I don’t think they are lying :smiley: and yes, the approach is only possible if you had a dedicated server and means to do a load balancer

You won’t be able to do it within the same site structure without some way to build a proxy yourself (Nginx or custom code), but you can certainly do it with CloudFlare or just DNS even with a shared server. I would still recommend CloudFlare and you can use the free plan to test it out.

The ideal solution with CloudFlare is to make sure the subdomain is set up and proxied along with your web site. So use or something. If both are proxied then the IP addresses of both urls (sGTM and your web site itself) will be in the same range and hence it won’t get flagged as a third party.

1 Like