Question

I am setting up a conversion funnel in Google Analytics and want to capture all product collection pages for my Shopify store. To do this, I want to match everything with this pattern: ^/collections/.* but I also need to exclude everything with this pattern:

^/collections/.*/products/.*

The reason being that collection(product category) pages follow this structure: /collections/[collection-name]

E.g.,

  • /collections/shoes
  • /collections/tshirts
  • /collections/hats etc

Product pages follow this structure: /collections/[collection-name]/products/[product-name]

E.g.,

  • /collections/shoes/products/pink-reeboks
  • /collections/tshirts/products/plain-white-tee

So I want to capture just the collection pages but not the product pages.

I have already identified a negative lookahead as the ideal way to do this. However, Google Analytics does not allow negative lookaheads, so I need another way to do this. Any help would be greatly appreciated!

Thanks in advance.

Was it helpful?

Solution

If you use ranges [a-zA-Z0-9] this won't match a \. See Rubular for a simple demo of this regex.

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

Of course you need to update your regex if you use collection tags within Shopify.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top