This is a list of my own helpful Regex strings for Google Analytics & Data Studio. Some examples are specific to Shopify & and some are more generic.
The intended use case is as a RegExp Match filter in GA or similar in GDS.
Limit to product URL’s / paths that exist under a collections URL:
This will only show you URL’s like this: https://mydomain.com/collections/top-sellers/products/my-products
In my example above, I wanted to see if a change I made to Shopify theme (to remove these URLs) actually dropped pageviews and landing page hits to those pages. Why I removed them is a separate discussion 🙂
Remove URL parameters (GDS):
I often use this as custom metric within GDS. It’s really a hacky workaround to bring some clarity to dirty GA data to see top pages. I use it to remove weird UTM params like fbclid’s, custom params, yotpo parameters, recommended product referral parameters etc.
REGEXP_REPLACE(Landing Page, '\\?.+', '')
Essentially the regex matches part of a string from ? char to anything. So anything question mark and following will be selected, and replaced with ” which is null string, so deleted. So in effect deleting URL parameters. As long as the other metric aggregation is working correctly within GDS they should aggregate okay-ish in GDS, but there are some gotchas, like I with like Ecom Transaction Conversion %’s adding by default which is not correct.
See home page only in Google Analytics
Seems like it should be simple, to filter to home page only but adding a simple text filter contains=’/’ to GA will show you all pages not just the home page.
URL parameters from uncleaned GA data can complicate this. Especially if you want to use logic like; match these:
/ /? /?something /?p=something
But not these:
/page/page /page/page?param=something /products/product-slug?p=something /collections/collection-name/?k=sdflksjdf909&rjnrid=1NqVnVx
So I’ll use a RegExp like this in GA to filter to home page only: