Testing Google Analytics Regular Expressions In Real Time

If you have a dynamic website and want to set up conversion goals within Google Analytics, you may need to use regular expressions to define the goal page.

These are extremely useful because they can be used to match specific sequences of characters in a URL. They’re a huge expansion on the common wildcard characters * and ? and tend to work out very well for ecommerce websites.

Here’s a typical example of how you can use them to great effect. Usually when you set up a conversion goal you have to specify a goal URL, that is, a page the user gets to which triggers that a conversion has taken place. In the case of an ecommerce website, it would be the receipt page, or “thank you” page once the user has purchased something. But in many cases the URL of that page is dynamic and may contain OrderID or CustomerID variables. Since this page changes every time, we need to use a regular expression so we can match the URL regardless of the value of those variables.

If you’re new to Google Analytics, you probably started off setting up a goal with your first attempt at a regular expression, going to your website to complete a test transaction, waiting approximately 3 hours then checking your stats. Not exactly the most efficient way of going about things, especially if you’re new to regular expressions.

If that’s the way you normally do it, here’s a massive time saving tip. You can test your regular expression live on previous data and it will take you just a matter of minutes to complete the goal.

1) Once logged in to Analytics, go to Content Optimization > Content Performance > Top Content
2) In the filter at the top of the screen enter your regular expression and hit enter.
3) Look at the content results and keep fine tuning your regular expression until you see the desired match appear

Here’s a real example used on an ecommerce site. The regular expression I used to filter the data was:

Click on the image to see a screenshot of the results:
Google Analytics Regular Expression Example

Just be sure to scroll through all results, to make sure it didn’t pick up anything else, otherwise your conversion stats will be overinflated.

More Help
Google Analytics Regular Expressions Syntax
Conversion University
Google Analytics Support Pages
Google Analytics Google Group

Edit: Corrected syntax, thanks Mark.

12 thoughts on “Testing Google Analytics Regular Expressions In Real Time”

  1. You give the example:


    however there is a tiny mistake in this. The full stop between you and asp is a regular expression character and should be escaped. At the moment this would match all of the following as correct /orderthankyou.asp, /orderthankyouaasp, /orderthankyouxasp, /orderthankyou1asp etc and while that will probably not be a huge issue it isn’t 100% correct. The correct form of the regular expression with the escape would be:


  2. Great little post. Not being a developer I’ve been fighting with expression logic in GA for week or more. Thanks again! Have fun in Columbus at the mini-SES. I couldn’t make SES NYC either, but I heard it was great. Go to PubCon in Vegas or to SES San Jose later this year or maybe SMX in June.

  3. Hi,

    One question. Why wouldnt you use regular expression not head match. ie paste http://www.wotever.com/orderthankyou.asp

    Head match is easier and recommended for simple goal setups, but sometimes sites have more complex needs. For example, a site that sells 6 products and has a contact form for each product, may want to track those form submissions. Since we only have 4 goals, we can set up one of them to track any of the 6 form submissions, as long as the forms have a similar path/file so w can match it with a regular expression.


  4. Hello,
    I found this post with Google, I thought it would help me but as you certainly know, Google changed the analytics interface and there is no more filter option. I guess I’ll use the old way: setting up my filter, waiting for some visitors and checking the results manually :)
    Thanks anyway!

  5. Davidn – The functionality is still there, go to Content > Top Content, the paste in the regular expressions into the field at the bottom of the page where it says Find URL:

    Then instead of the plus and minus icon from the old interface, you use the dropdown box to specify ‘containing’ or ‘excluding’.

  6. oh, yes, sorry… I saw “containing” and “excluding” and thought it didn’t work with reg exp, but it does, great!
    The problem is that I still have 0 goals but there should be from yesterdays visits, and there are matches in the top content using the same reg exp.. :/
    I’ll check that. I may need to include the full domain in the goal option (according to the example) but not in top contents.

  7. Hi,
    I also stumbled about this post while doing some searches on Google. I didn’t know that it is so easy to test regex in Google Analytics itself. :) Great!

  8. I have a dev server setup locally, that is of course not accessible from outside the company…

    i want to test my analytics code on it…preferably real time…

    how do i do it?

  9. Hi, i found your article very useful and promptly started to try to capture clicks on one of my page.

    However my analytics conversion goals were zero even if i know that i’ve made tests just to increase the conversion goals sl as to see results in GA.

    here’s one of the code i implemented:

    and my regular expression in GA is:

    Not sure if my regular expression is the right one to use..

    Can anyone give me some advice on this, cause am struggling to the the figures right.



  10. Thanks – highly informative.

    I am having a problem getting Analytics to list my conversion URL. Because I use a hosted shopping cart, the checkout URLs are on another domain name and I have very little control.

    The only thing I could think of was to add an anchor to my order receipt page and then do a javascript redirect so my order receipt URL has “#my_anchor” on the end. I then use a regular expression to match this text.

    However – when I look in the Top Content, I can not find my anchor text anywhere in Analytics (and it is not because there are too many URLs and I’m just not finding it).

    Any suggestions? Is there a better way to track Goal conversions in Google Analytics?

Comments are closed.