I have multiple environments for my web app to run: localhost, testing and then production.
I want to have the same GTM code but to somehow tell GTM to filter out everything besides real requests on my production server (could be done by domain, example.com).
I know I can do this in JS where I check hostname and don't include the tag code if hostname is not my main domain but I would like a solution that I configure on GTM so that i'm 100% sure that is working and I'm not getting wrong data on it.
What I can't have is a different codebase for each environment.
What's the best way to manage this?
There is a built-in variable in GTM called Page Hostname, so you can set it as a condition for your tag's triggers. For example, you may change a Google Analytics tag's trigger from All Page Views
to Some Page Views
, where page hostname matches your site's hostname.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With