Categories
Uncategorized

Some RegExp for Shopify

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

Match these:

https://mydomain.com/collections/top-sellers/products/product-slug
/collections/round/products/red-spinning-top

Not these:

https://mydomain.com/products/my-products
/products/red-spinning-top

RegExp here:

\/collections(.+)\/products\/

Example:

Screenshot from Google Analytics showing only Shopify product page paths in collection

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 here:

REGEXP_REPLACE(Landing Page, '\\?.+', '')

Example:

This is a GDS screenshot where I’ve setup a Custom Metric.

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.

Match these:

/
/?
/?something
/?p=something

Not these:

/page/page
/page/page?param=something
/products/product-slug?p=something
/collections/collection-name/?k=sdflksjdf909&rjnrid=1NqVnVx

RegExp here:

^\/$|^\/\?

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.

Match these:

http://www.website.com/collections/[collection-name]

Not these:

http://www.website.com/collections/[collection-name]/products/[product-name]

RegExp here:

^/collections/([a-zA-Z0-9]|-)*$

RegExp to match Shopify collection + home pages

Useful if you’re trying to setup a funnel first step in some analytics tracking for example.

(^/collections/([a-zA-Z0-9]|-)*$)|(^/$)

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:

Match these:

/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

RegExp here:

collections\?|collections$|collections/$|collections\/\?

Here’s a test case to demo it.

More examples

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.

Leave a Reply

Your email address will not be published. Required fields are marked *