How do I only allow google analytics 4 to get data from my approved domains rather than things like localhost etc? Does this feature exist?
So far [December 2020], there’s actually no way to create a valid hostname filter in GA4. You have to create a segment in the interface to analyze the data that interests you.
Filters in GA4 will probably not be added the way they were working for UA unfortunately.
There are a number of ways to go around this in order to "filter" out certain type of traffic such as localhost or other staging/test environments to be collected in your GA4 property.
You could create exception triggers in GTM that trigger whenever one of your tags fire from a test environment, this way the tags will "block" certain type of traffic from being collected in your GA4 property.
Another way to do this (my recommendation) is to create 2 separate GA4 properties, one for production and for staging (Master or Test). Then simply create a lookup table inside GTM and add it in your configuration tag as measurement id, where you add the domains and the measurement ID as output. So if the traffic originates from localhost send to G-1234 etc. This way the data would't be blocked in any way. A tip is to set a default value in the look up table so that all hostnames that aren't specified in the look up table sends data to the test property.
Hope it helps!
© 2022 - 2025 — McMap. All rights reserved.
Engagement > Pages and screens
– Provencal