The Content Authority Blog

This Blog Is Written By The Content Authority

Regular expressions (RegEx) have some useful applications in Google Analytics. You can use them to create more accurate and versatile tracking scenarios than are available by default on the platform. Regular expressions are essentially special characters that instruct Analytics on which sets of data to capture and record. This post will highlight some scenarios where regular expressions are useful.

Regular Expressions in Google Analytics Goals

You can utilize a RegEx when setting up a goal in Analytics. Using this method for a goal is best when the URL is variable. Head match is another good option, but the regular expressions gives you a bit more control if implemented properly. The cool thing about regular expressions with goal URLs is that you can write your regular expression to match any part of the URL exactly and the rest of it to be variable. For instance, using the dot . matches any single character, the carat ^ tells analytics that your data must be at the beginning of the field and the * tells analytics to match zero or more of the preceding character. If you wanted to match a URL that always began with /regex but was always variable after that term, you could write ^/regex\./.*.  Note that the . after the word regex has a back slash before it. This tells Analytics that the dot is actually a dot and not part of the expression. The period after the star is actually ending my sentence. The characters .* tells Analytics to match anything.

To use regular expressions in goals:

  1. Log into your Analytics account.
  2. Click on the Admin button in the top right corner.Using regular expressions in Google analytics goals
  3. Click the profile you would like to create a goal for.
  4. Click the goals tab.
  5. Click +Goal.
  6. Select URL destination for the Goal Type.
  7. Make sure you select regular expression match from the Match Type drop down menu.Google Analytics Regular Expression Dropdown

Excluding IP Addresses from Analytics Data

Another use for regular expressions is to exclude data from being collected based on user IP address. This is a common filter in Analytics that allows users to exclude things like their own machine or perhaps a contractor’s machine if there is work being performed to a website. Another reasonable use is the desire to exclude employee traffic from a profile so that more accurate data can be gleaned from a website used by a business. Businesses, especially larger ones, utilize dozens, hundreds and even thousands of computers. Entering in an IP address for every single machine is not practical, and also would not be effective. For these purposes, a range of IP addresses written as a regular expression works to exclude employee or other unwanted traffic from reports.

You can use all of the same regular expression rules that you would use for capturing specific URLs in your goal above; however, Google has a really great tool if you are excluding one or more IP addresses from data. It’s called the IP address range tool, and all you have to do is enter in at least one IP address and click the “generate RegEx” button. You then simply copy and paste the snippet of characters into your filter field.

IP Address range tool

 

To set up a filter excluding one or more IP addresses:

  1. Log into your Analytics account.
  2. Click the Admin tab in the top right hand corner of the page.
  3. Select the profile that you want to set your filter up in.
  4. Click the filters tab.
  5. Click the +New Filter button.
  6. Create new filter will be selected by default.
  7. Select the Custom Filter radio button.
  8. Select the Exclude radio button.
  9. In the Filter Field drop down menu select IP Address
  10. Paste your RegEx from the range tool into the Filter Pattern box.
  11. Make sure the “no” radio button is selected for Case Sensitive.
  12. Click save.

Be sure you are applying this filter to a copy of your default profile. You never want to apply filters to the default profile. Always apply filters to copies of the default profile. That way, if something is done wrong or, for some reason, you want to look at the data again, it will still be there.

Excluding Data in Reports

Another handy use for the RegEx is to exclude or include specific URL or other data from reports. This trick is cool because you aren’t actually changing any of your data — you’re just telling Analytics to do it for that moment in that specific report. After you leave that report or Analytics in general, your reports go back to normal. For instance, in your content reports, you just click on the advanced dimension filter and let Analytics know which pages you would like to see or not see in the report.

To use regular expressions to exclude URLs from content reports:

  1. Log in to Analytics.
  2. Select the content report that you want to manipulate.
  3. Click on the link that says Advanced at the top of the report.In Report Regular Expressions
  4. Choose include or exclude depending on your purposes.
  5. Note that you must use a Dimension in order to use a RegEx.
  6. Make sure “Matching RegExp” is selected.RegEx in Reports
  7. Write your regular expression in the box and then click Apply.

This use of the RegEx is particularly useful when sifting through many URLs that may be very similar. You can then only view the ones that have a particular parameter in them, for example. Note that you can add more dimensions and other regular expressions if you wish; however, you must remember how Analytics applies these. It will apply the filters in the order in which they are applied to the report (the first one first). Subsequent filters may not work if you have thrown the data out or told Analytics to keep it using the first filter in the series.

Writing regular expressions can be very confusing at first. It is almost like learning a new language, but is even more cumbersome because they use characters that already have alternative (and well-worn) meanings for us. There are tons of great resources on the web for learning about regular expressions. Remember to create duplicate profiles in your Analytics account so that if you make a mistake or want your data back when dealing with filters, it will still be around.

You can learn more about using regular expressions in Google Analytics here.

How do you use regular expressions in Analytics? Do you find them confusing or have you mastered them already? Let us know what you think by leaving a comment or dropping us a line.

 

About Shawn Manaher

Shawn Manaher has written 384 post in this blog.


Loading Facebook Comments ...
There are no comments.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

End Comment -->
Navigation