Google Analytics Regular Expression Examples

Few years ago I was training a group of analysts on Google Analytics and when moved to topic of regular expressions one of the trainees casually mentioned that those strange symbols looked very irregular to be called regular expressions. 

What are regular expressions?

Regular expressions are equivalent of SQL queries for set of text rather than a relational database. In simple words you can use regular expressions to query text and filter patterns of the texts that you are looking for. 

 

How can you use regular expressions in Google Anlaytics ?

  • Filtering dimension rows: Regular expressions can be used to filter rows of report as shown in the screenshot below.

reports

  • View Filters : Regular expressions can be used to create filters for your views

filters

  • Segments : Regular expressions can be used to create segments based on regular expressions

segment

  • Custom reports : Regular expressions can be used in custom report configurations

custom reports

With regular expressions I have solved numorous reporting challenges and here are some common use cases for regular expressions.

1 Use Case Regex
2 Dimension value "This" OR "That"  This|That
3 Dimension value starts with "This" ^This
4 Dimension value ends with "This" This$
5 Dimension value has number [0-9]
6 Dimension value has at least 2 consecutive numbers  [0-9]{2}
7 Dimension value has at between 3 to 5 consecutive numers  [0-9]{3,5}
8 Dimension value has at least one letter [a-z]
9 Dimension has at least one space /s
10 Dimension spelling variations by missing a letter Google or Gogle  Goo?gle
11 Dimension spelling variation by different letter Google or Gougle  Go.gle
12 Dimension spelling variation by different, missing or extra letters Google or Gougle or Gooogle Go*gle
     

This doesn't cover your use case? Post a comment or tweet with #GAregexHelp and I will update this page with your use case. 

Last modified onSunday, 17 July 2016 15:18
Nikhil Parachure

Nikhil is nothing short of "Swiss Knife of Digital Marketing". Over  the course of last 10 years he has been involved in practically every facet of Digital Marketing and Analytics.

Starting career with paid search, Nikhil has built and managed award winning digital campaigns, has been Google Adwords Top Contributor, Planned and implemented several complex and large scale web and mobile analytics implementations. Currently working for Myntra as Manager Analytics Nikhil is also conducts trainings on Web Analytics, Mobile Analytics and Digital Marketing.

 

Website: www.theniks.com/

3 comments

  • Mike

    Mike

    Comment Link Monday, 18 July 2016 11:44

    Hi Nikhil,

    Thanks for the answer, but I feel like I didn't explain my scenario well enough.

    I want to be able to look at the different levels of engaged users on my site - now they have to log in so I will know that if there is traffic, it is because someone has decided to log in and interact with the site.

    Is there any way I can check on a monthly basis and separate the users who have logged in at least 3 out of the 4 available weeks that month and compare them against users who have logged in two times out of the possible 4 weeks?

    Is this possible to do in GA?

    Report
  • Nikhil Parachure

    Nikhil Parachure

    Comment Link Sunday, 17 July 2016 10:49

    HI Mike,
    By Interactions do you mean number of events and pageviews user has does with your website?
    If that is correct assumption then you dont really need regex for this. You can create a segment with condition as hits 0.
    If you want to do this only for events then you can create a similar condition for total events

    Report
  • Mike

    Mike

    Comment Link Sunday, 17 July 2016 08:25

    Hi Nikhil, how would you implement regex to split users into groups?
    For example, if a user decides to interact X times with your site (custom event tracking) I would then like to segment them by how many times they interact.
    So 1 segment for between 1-5 times, another for 6-10 times and so on and so forth.

    Many thanks,
    Mike

    Report

Leave a comment

back to top