Leveling up RegEx in GA Filters

Level Up the RegEx

RegEx 101 Example

Advanced filters in Google Analytics can be used to clean your data as it’s being recorded. We used them in a previous blog post and this article extends on that idea. Today we’re going to level up our use of regular expression in Google Analytics Advanced Filters.

Regular Expressions are used by GA Filters, in the previous article we used regEx to match a product id that is more than three digits. We did this using the regular expression:

 

 

^(/.*/)(\d{3,})(.*)
URI input: /product/123456/warranty

 

 

This regular expression is true when the Request URI begins ^ with a root folder (/.*/) followed by three or more digits: (\d{3,}). Finally, we capture the remainder of the URI using (.*). We used groups () to extract the values and will be used in a later step.

GA Advanced Filters can persist groups extractions from Field A and Field B. We use this feature to reconstruct the Request URI using the Output To -> Constructor:

$A1{id}$A3
URI before: /product/123456/warranty
URI after:  /product/{id}/warranty

 

$A1 extracts the 1st group from Field A. $A3 would extract the third group from Field A, if it were to exist. {id} is a static string that is a placeholder for the dynamic value.

If the product id was a mix of alphanumeric, then we’d need to use a different match pattern. Here are a few examples of common id patterns found in URLs:

 

[A-Z]-\d+ // matches Z-764537389 
\d{4}-\d{3}-\d{2} // matches 1234-123-12

 

If you have a RFC4122 compliant UUID in the URL you need match?

 

[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12} 
 // matches 0df98a02-c438-4c57-8d1c-2f6041804e2c

 

GA Advanced Filter RegEx is case insensitive by default, this can be overridden in the filter settings.

Be sure to let us know about all the wild RegEx patterns you come up with in an effort to wrangle your data! Using filters can be a very rewarding experience, albeit a laborious one. We are here to help! Don’t forget to check out our free-to-download RegEx cheat sheet. Tweet us at @AnalyticsPros and keep in touch!

Leave a Comment