Jump to content

Google Analytics - match specific parts of url


CroNiX

Recommended Posts

For google analytics, I need to have a regex that will match our goal pages.

 

The part of the url that it would be looking at would be similar to:

/variable/checkout/variable/thank-you

 

These urls will have exactly 4 segments. "variable" segments can contain only letters (case insensitive), numbers, dashes and are required.

I need to specifically match "checkout" in the 2nd segment and "thank-you" in the 4th.  There is no trailing / after thank-you.

 

Any help would be greatly appreciated.  Regex is my weakness.  (I know...I know..)

 

Well, the individual letters in each segment would be [a-z0-9-] (add a A-Z if the regex isn't already case-insensitive), and to have more than one use a + quantifier. The rest is basically just a literal copy of the URL you're matching.

\/+[a-z0-9-]+\/checkout\/+[a-z0-9-]+\/thank-you
 

 

This seems to work, at least when testing with preg_match(), does it look correct with the rules I stated?  I basically escaped all slashes and chained everything together with a + that wasn't static.  I think (lol)

A little too overzealous with the pluses.

/[a-z0-9-]+/checkout/[a-z0-9-]+/thank-you
You might not need to escape the slashes (they'd probably tell you to if you did) and you might need ^ and $ anchors (if they say anything about it matching parts of the URL and not the entire thing).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.