Filtering GA like a boss
- doug56778
- Oct 1
- 2 min read
This article will present two ways of filtering your data in GA. If you want to keep your production data nice and clean, you want to be able to report on production data only. Seems obvious but often you'll find data generated by Preview Mode in GTM.
We're not advocating for testing in production but sometimes you need to trace down something that's broken...right?!
Anyway, two ways to filter data - one for those using client side GTM only, and one for those using server side data collection.
Client side first.
Client Side Preview Mode Filtering

Click Create

Set the parameter to container_version.
You'll need to send container_id and container_version as event parameters. We recommend doing this using the GA Event Settings variable
Set the operator to equals QUICK_PREVIEW.

Modify the parameter by setting traffic_type = dev for all matching events.

Click Save.
In the last step, Create a data filter (internal traffic type) where you exclude all traffic meeting traffic_type = dev. Setting the Data Filter to test mode or it will begin to filter the data out…
Server Side Preview Mode Filtering
This is trickier than client side as the server container or the client side container can be in preview mode... So we use a Server side GTM transformation to recognise when either container is in preview mode.

This requires the client side container version to be present as an Event Data variable.
Use the event settings variable to apply the event parameters consistently as mentioned above.
But! Transformations don’t support OR logic in Matching Conditions so applying the transformation when this container is in Preview Mode OR that container is in Preview Mode has a challenge.
You have options:
Duplicate the transformation (not a fan)
Write a variable using a custom variable template (don’t like or can’t maintain JS?)
Chain Lookups
I chose to chain a pair of Lookup variables:
If the server side container is in preview mode, return True to activate the transformation:

If it’s not, check the client side container version:

If one of the containers is in preview mode, the variable will return True and activate the transformation.

Validation:
Check in server side and client side preview mode. Test the direct effect of the transformation on the GA4 tag:

Now you can start filtering, calibrating, and debugging data without affecting production data:

The traffic_type dimension can be used in a report filter:

Be careful when configuring a property level filter - make sure the Filter state is set to 'Testing' initially - don't filter data until you know it's correct. Filtered data is filtered permanently:

You can test the filter in reports by selecting 'Test data filter name" from the General list of secondary dimensions.

. You might choose to change the names for clarity, or add report filters, or even make the property filter fully active.
You can now use transformations or event modifiers to adjust data in a range of scenarios. Be aware the transformation is done server side, and the event modification is done client side so you can't modify an event based on a transformation output. Trust me on this, I tried it :-)


Comments