Andre Santos
Andre Santos

Reputation: 113

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?

Upvotes: 11

Views: 8094

Answers (1)

Дмитро Булах
Дмитро Булах

Reputation: 3847

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

Upvotes: 21

Related Questions