Fixing GA4 Data Bloat: How to Strip WooCommerce Filter Parameters (Without Killing Your UTMs)
When managing a WooCommerce store, faceted navigation can quickly ruin your Google Analytics 4 (GA4) data. Every time a user filters by color, size, or price, WooCommerce appends query parameters (like `?filter_colour=blue`), creating thousands of fragmented pageview rows for the exact same category page.
The common fix is to strip out query strings before sending data to GA4. However, a blind truncation will accidentally delete your marketing attribution data—destroying Google Click IDs (`gclid`), Meta pixels (`fbclid`), and UTM tracking parameters.
The solution?
Selective parameter stripping via Google Tag Manager (GTM)
The script below surgically targets default WooCommerce filter parameters while keeping your critical marketing tracking completely intact. Follow these steps to implement it for your WooCommerce store.
Step 1: Create the Custom JavaScript Variable in GTM
- Log into your Google Tag Manager container.
- Navigate to Variables on the left menu, and click New under User-Defined Variables.
- Name the variable something clear, like CJS - Clean Page Location.
- Choose Custom JavaScript as the variable type.
- Paste the following code into the editor:
function() {
var url = window.location.href;
var urlParts = url.split('?');
if (urlParts.length < 2) return url; // No parameters, return early
var baseUrl = urlParts[0];
var params = urlParts[1].split('&');
var cleanParams = [];
// Define the exact WooCommerce parameters to strip out
var stripList = ['filter_', 'min_price', 'max_price', 'orderby', 'per_page', 'paged'];
for (var i = 0; i < params.length; i++) {
var param = params[i];
var key = param.split('=')[0];
var shouldStrip = false;
for (var j = 0; j < stripList.length; j++) {
if (key.indexOf(stripList[j]) === 0) {
shouldStrip = true;
break;
}
}
// Keep marketing tags (UTMs, gclid, fbclid) safe
if (!shouldStrip) {
cleanParams.push(param);
}
}
return cleanParams.length > 0 ? baseUrl + '?' + cleanParams.join('&') : baseUrl;
}Step 2: Update Your GA4 Configuration Tag
- Once the variable is created, you must instruct your GA4 tag to report this "clean" URL instead of the actual browser URL.
- Go to Tags in GTM and open your primary Google Tag (the one utilizing your G-XXXXXXXXXX measurement ID).
- Under Configuration settings, add a new parameter row.
- Set the Configuration Parameter to: page_location
- Set the Value to your newly created variable: {{CJS - Clean Page Location}}
- Save the tag.
How to Verify the Implementation
Before publishing the workspace container, use GTM's Preview Mode to ensure it works correctly:
- Click Preview in GTM and navigate to a heavily filtered URL on your site (e.g., [yourstore.com/shop/trainers/?filter_colour=blue&utm_source=newsletter](https://yourstore.com/shop/trainers/?filter_colour=blue&utm_source=newsletter)).
- In the Tag Assistant window, click on the Container Loaded or Page View event.
- Click the Variables tab and look for CJS - Clean Page Location.
- Expected Result: The variable value should output [yourstore.com/shop/trainers/?utm_source=newsletter](https://yourstore.com/shop/trainers/?utm_source=newsletter) (the filter_colour is completely removed, but the utm_source is perfectly preserved).
- If everything looks clean, click Submit and Publish your GTM container.
By implementing this you fix the Analytics Distortion Problem on WooCommerce filter URLs corrupting your GA4 data.

Founder, Technical Analyst
Oladoyin Falana is a certified digital growth strategist and full-stack web professional with over five years of hands-on experience at the intersection of SEO, web design & development. His journey into the digital world began as a content writer — a foundation that gave him a deep, instinctive understanding of how keywords, content and intent drive organic visibility. While honing his craft in content, he simultaneously taught himself the building blocks of the modern web: HTML, CSS, and React.js — a pursuit that would eventually evolve into full-stack Web Development and a Technical SEO Analyst.
Follow me on LinkedIn →