9 Google Analytics Regex Tricks For Power Reporting

Regular Expressions is probably the most underutilized feature of Google Analytics. Regular expressions can take your reporting to next level, save a ton of your time which you invest in spreadsheet jugglery and help you get to data which can not be explored without regular expressions.

Regular expressions which are also known as Regex or Regexp is a mathematical concept from the 1950s but came into common usage in 1980s with Unix text processing utilities. Regular expression is a method used to find specific patterns or combination of characters within the text. Google Analytics uses regular expressions for the same purpose and using this technique you can build powerful filters and segments to make your reports more granular and insightful. This article is going to provide you with xx regex tricks. You can use these tricks right out of the box without investing time in learning complex regular expression technique.

Where Can I Use Regular Expressions in Google Analytics?

Regular expressions are usually used as filtering or searching techniques and in Google Analytics you can use these in several features.

  1. View Filters: You can use regular expressions in Google Analytics view filters in admin section
  2. Report Filters: You can use regular expressions in Google Analytics report filters at the top of each prebuilt report. In this article, I will be using report filter in all examples.
  3. Segments: You can use regular expressions in Google Analytics segments to define your user or session segments.
  4. Custom Reports: While building custom reports regular expressions can be used to filter dimensions as well.

Google Analytics Regex Trick #1: Using “Or” Condition

While building reports you must have come across a challenge where you would like to filter a report for dimensions you need with or condition. For example, a report in which you want metrics to be reported for mediums (none) or organic. If you try achieving this with Google Analytics filter combinations it will be impossible as It GA filter combination only provides “And” conditions as shown in the screenshot below.While building reports you must have come across a challenge where you would like to filter a report for dimensions you need with or condition. For example, a report in which you want metrics to be reported for mediums (none) or organic. If you try achieving this with Google Analytics filter combinations it will be impossible as It GA filter combination only provides “And” conditions as shown in the screenshot below.

Google Analytics Advanced Filters
Google Analytics Advanced Filters

 

 

 

 

 

 

But you can achieve this easily with regular expressions by choosing medium matching regex (none)|organic. In this example regex metacharacter “|” works as “Or”. You can also use “|” between your words for multiple “Or” statements as well, e.g. (none)|organic|cpc|referral.

Regular expression or statement
Regular expression or statement

 

 

 

 

Google Analytics Regex Trick #2: Using “Begins With” Condition

Another common requirement which most analysts come across is filtering dimensions by characters at the beginning. For example a report with sources which start with “Google”. Again this can be easily achieved with regular expressions by using “^” sigh which is also known as “Caret sign”. For the example above you can write a regular expression “^google”. The symbol caret is equivalent of “Begins with” in regex metacharacters.

Google Analytics Regex , Begins with
Google Analytics Regex, Begins with

 

 

 

Google Analytics Regex Trick #3: Using “Ends With” Condition

After understanding how “begins with” works in regex, this example is the exact opposite. “$” is a character which we usually associate with US dollars, but in case of regex “$” is a symbol which is used to denote condition “ends with”. For example, in referral report, you want to create a report with only “.net” domains. For this example, the regular expression in report filter will be “^net”.

Google Analytics Regex Word Ends with
Google Analytics Regex Word Ends with

 

 

 

 

Google Analytics Regex Trick #4: Using Unknown Character

Imagine you want to report pageviews for pages where URL contains words pat or hat or bat or cat. Essentially you want to report pageviews for every URL that contains a 3 letter word which ends with “at”. If you know all such words which may appear in your URL you can always use “Or” method which is defined in trick #1, but a simpler and more efficient way of achieving this is with regular expression “.at”. In this example, we are using regular expression metacharacter dot (.) which matches any character in place of (.) dot. Which means it will filter values such as bat, pat, fat, mat, etc but it will not match “at” because (.) dot will need one character to be matched in its place. This metacharacter comes in handy especially in view fitlers for excluding internal traffic with IP address.

Dot regular Expression
Dot regular Expression

 

 

 

Google Analytics Regex Trick #5: Using For Misspellings

I often face challenges when I am looking for search terms with my last name in the search term report. My last name is spelt in 2 ways “Parchure” and “Parachure” if I want to filter both terms in a report “?” as regex metacharacter comes in handy. “?” means the last character before “?” is optional and “Para?chure” will filter for “Parchure” as well as “Parachure”. This is a great way to filter for misspellings or a different type of spellings. A classic example of this is “Color” vs ” Colour” some users may use “Color” as search term while others may use “Colour” but the intent of both is same. This can be easily filtered with regular expression as “colou?r”.

Optional character regex with question mark
Optional character regex with question mark

 

 

 

Google Analytics Regex Trick #6: Using Range

Using question marks or dot may help you create a filter where 1 character is in doubt but if you want to run an exercise where several characters can be optional or is one of many probabilities.  But when you have to do this for several characters it’s practically impossible to use question marks or dots. This is where ranges come in to picture. For example, if you are creating a filter for keywords where keyword contains either of pat, pet, pit, pot or put. One way to achieve this is by using the pipe as described in  trick#1. But using pipe may not be possible or may not be the most efficient way of achieving this if there are multiple possible values. This is where range works best, so for example above a regular expression “p[aeiou]t” will match all of the terms. By using square braces you can give range to match one or more characters from the range. For example, [abc] matches a , b or c , [123] matches 1 , 2 or 3.

Google Analytics Regex Trick #7: Making Range More Powerful with Dash (-)

With previous trick we took a step ahead of simple regular expression to use ranges using dashes adds another layer of power to your regex arsenal. For example, if you are looking for a URL which has word /contactme/ followed by a random number you can use a regular expression as /contactme/[0-9]. Similarly, if you are looking to match any character instead of a number you can use range as [a-z].

Google Analytics Regex Trick #8: Range Matching In Top Gear

This trick takes range matching to top gear. In 2 previous examples of range matching the limitation was on specifying number of characters to be matched using curly braces “{}” solves this problem as well and puts range matching in top gear. Let’s take a look at examples from the previous trick with a little twist. If you are looking for URL which has word /contactme/ followed by random numbers between 4 and 6 digits, e.g “/contactme/3466”, “/contactme/34665”, “/contactme/346567”. The regex to match this using curly braces will be /contactme/[0-9].

Google Analytics Regex Trick #9: Follow #TrackingSOS On Twitter

For all updates on Google Analytics tune in to #trackingSOS on twitter and if you have any issue/questions about Google Analytics ask your question on Twitter with #trackingSOS.

Want to stay tuned for Google Analytics updates? Sign up for my weekly newsletter for latest on digital marketing and analytics.

Sign up & Get Free Google Analytics Audit Tool!

 

 

Please follow and like me:
565

AuthorNIkhil 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 a leading ecommerce platform in India as Head of Digital Marketing Nikhil has also conducted analytics and marketing trainings for several MNCs.

Leave a Reply

Your email address will not be published. Required fields are marked *