Common RegEx for Google Analytics

Category : Google Analytics

Regular Expressions (RegEx) = characters used to define a search pattern

RegEx seems like a massive headache once you start expanding beyond standard pipe (|) usage. But if you learn a just a few more basic characters, you can create more specific filters in GA, and also use them to define filters in DashThis instead of creating segments.

Common Characters for GA:

  • Pipe (|) = means or
  • Caret (^) = means begins with
  • Dollar Sign ($) = means ends with
  • Period-Asterisk (.*) = matches zero or more random characters

Example:

We want to analyze metrics for the home page plus a few select pages on a site….

Filter = Include Page matching RegEx ^/$|^/mens-clothing$|^/womens-clothing$|^/kids-clothing$

Note – The string above will exclude any URLs with tracking parameters or sub-pages. If we wanted to include them in our Analytics report, we would need to use Period-Asterisk (.*)…

Filter = Include Page matching RegEx ^/$|^/mens-clothing.*|^/womens-clothing.*|^/kids-clothing.*

Google Analytics = https://online-metrics.com/regular-expressions/

DashThis = https://dashthis.com/support/google-analytics-filters-and-segments-all-you-need-to-know/