I started this list of Regex strings that I find useful in Google Analytics & Google Data Studio. Some examples are specific to Shopify & and some are more generic.
The intended use case for something like RegExp Match filter in GA or in GDS; custom metric formulas.
RegExp match Shopify product URL’s under collections only
- RegExp match Shopify product URL’s under collections only
- Strip out URL parameters in Google Data Studio
- RegExp match home page only
- RegExp to match Shopify collection pages only not product pages
- RegExp to match Shopify collection + home pages
- Regexp match the collection list URL in Shopify
- More examples
In the 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 🙂
Strip out URL parameters in Google Data Studio
I often use this as custom metric within GDS. It’s bit of a hack workaround to bring some clarity to dirty GA data that has been tainted with dirty URL parameters. If you want to see a clean list of top landing pages ignoring appended URL params, this helps a lot.
For example if you have 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.
RegExp match home page only
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. This is not unique to Shopify.
This is useful if you have a lot of messy URL parameters that have yet to be cleaned up. This could be things like eDM referrer URLs, SMS traffic URL’s. Or other custom parameters attached to destination URLs that work their way into GA without having been intentionally filtered out or dropped at point of collection.
/ /? /?something /?p=something
/page/page /page/page?param=something /products/product-slug?p=something /collections/collection-name/?k=sdflksjdf909&rjnrid=1NqVnVx
RegExp to match Shopify collection pages only not product pages
This is one of my favorite ones as it lets you quickly segment out the performance of collection pages.
RegExp to match Shopify collection + home pages
Useful if you’re trying to setup a funnel first step in some analytics tracking for example.
Regexp match the collection list URL in Shopify
For example if you want to see the domain.com/collections page with and without slash, with and without random URL params and but not actual collections pages themselves. Eg:
/collections/ /collections/? /collections /collections? /collections/?somerandomdfsfdf=sdfl90890 /collections?somerandomparam=lkjkljl&anotherparam=xyz
Don’t match these:
/collections/collection-name-a/ /collections/collection-name-b /collections/collection-name-b/?sdfsdf=asdf90d
Here’s a test case to demo it.
If you have any other regexp ideas, examples, improvements, tips or tricks you use to better under Shopify data in web-analytics, I’d love you to drop a comment below or send me an email: hi [at] this domain.