Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter Google Tag Manager to only my main domain ( exclude testing environments )?

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?

like image 793
Andre Santos Avatar asked Jan 27 '23 03:01

Andre Santos


1 Answers

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. enter image description here

like image 53
Дмитро Булах Avatar answered Apr 28 '23 11:04

Дмитро Булах