For most Google Analytics users, including web analysts, regular expressions can be daunting. However, even a basic understanding can greatly help you on your path to master Google Analytics.
In this blogpost I will share why you want to know more about regular expressions and where to apply them in your Google Analytics account.
I am sure that following my tips will greatly improve your Google Analytics set up and analysis. Let’s take a brief look at the main list of regular expressions:
Regular expressions are characters than help you define, include or exclude data in Google Analytics. Every time I visit the Google Analytics forum to provide help, I see many questions popping up about regular expressions.
There are (at least) six different cases where they really come in handy:
- Creating filters in admin section
- Applying table filters
- Setting up (destination) goals
- Defining a goal funnel
- Creating segments
- Creating custom reports
In my opinion, these are all vital features of Google Analytics. If you get them wrong both your data reliability as well as insights will suffer.
1. Creating Filters in Admin
As you might know, filters determine what data is collected in each of your views.
In an earlier post, I wrote about six data views you should always set up.
When setting up filters, one of the best practices is to filter traffic on your IP since it pollutes the data in your account.
Here is how the filter looks like:
This regular expression ensures that I only filter out my IP address.
In another situation, let’s assume you have a multiple domain implementation with Universal Analytics measuring www.testA.com and www.testB.com. In this era of *SPAM* traffic you want to use an include filter on your hostnames.
Note: setting up two include filters on hostname will return zero data so you need to set up a filter that includes both hostnames.
This is where regular expressions are your best friend.
There are actually many filters that involve regular expressions to set them up correctly.
2. Applying Table Filters in Reports
Google Analytics let’s you filter the data in any way that you want and in this example I will show you a few reports on my marathon website:
Not too long ago, the field shown above didn’t accept regular expressions. Happily this has changed.
Let’s assume you only want to include pages that contain running or half. In this case you need to fill in running|half.
Now I will remove the extra “space”.
As you can see, you have to be very careful when using regular expressions as an extra space or wrong characters lead to incorrect or no results.
Read this table filters guide if you want to learn more about table filtering in general.
3. Setting up Goals
Without well-defined goals you can’t optimize your website. You will probably already guess it, regular expressions are very useful in setting up goals as well! In the past I was always complaining about the goal settings “exact match” and “head match”. Why? Simply because they were confusing for a lot of people … and you know what, they have changed it! 🙂
For example, you sell bicycles and have three category pages:
- /bikes/men
- /bikes/women
- /bikes/kids
These category pages are very important to you and you want to correlate the unique views against traffic sources, destination pages etc.
However, you only want to include “men” and “women” in your goal set up.
Two known regular expressions and a new one (). This helps you to keep the regex length to a minimum and include both “men” and “women” category pages.
Once again, without using regular expression characters you cannot set this up as a (combined) goal.
4. Defining Goal Funnels
I won’t elaborate too much on goal funnels here. You can set up goal funnels for a specific journey on your website and you might need to come up with a regular expressions in some or each of your funnel steps.
One more tip here; below the goal settings you can verify your goal. I recommend always taking this small step if you have already data collected to verify your goal set up. This will ensure your goal set up will work fine.
You can also navigate to Behavior > Site Content > All Pages and use the table filter to verify your goal URL. This only applies to destination page (URL) goals.
By now I hope you realize that regular expressions are so powerful and should be in your Google Analytics arsenal!
Wait! We’re not done … there are 2 more things I like to share.
5. Creating Segments
In my opinion, segments are one of the most powerful features in Google Analytics. They provide you with lots of flexibility to analyze and optimize the main KPIs of any website!
Averages lie so you need to dive deeper. This is when segments are your best friend and again, regular expressions really help you to dig deeper and find insights.
In the earlier table filter example I filtered my data on pages that include the word “running” or “half”. Now I would like to know which media drive the most traffic to pages that include the word “running” or “half”.
Step 1: Build a segment that includes landing pages with the word “running” or “half”
Step 2: Navigate to “traffic sources” report in Google Analytics and select medium as first dimension
You could select the “all sessions” segment if you would like to compare the distribution of this segment to what’s happening overall on your website.
This is just a simple example of using regular expressions when defining segments in Google Analytics. They help you to build any segment you will ever need to dig deeper, find insights and improve your business!
6. Creating Custom Reports
Custom reports are great and help you bring together all the metrics and dimensions that are relevant to your business and once again, regular expressions are great in leveraging custom reports.
Here is an example of a custom report with a regex applied:
In a custom report you can use regular expressions to filter on the data. It’s great if you have a need to build more advanced custom reports.
Well, this is it from my side. I hope to have encouraged you to use regular expressions on a more regular basis! One more thing … I have put together a thorough guide on regular expressions you might want to checkout as well.
Thank you! Very helpful and detailed. I wish there were more in-depth tutorials like that.