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:
^/orderthankyou\.asp.*
Click on the image to see a screenshot of the results:
![]()
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.

(4 votes, average: 4 out of 5)

April 11th, 2007 at 8:58 am
You give the example:
^/orderthankyou.asp.*
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:
^/orderthankyou\.asp.*
April 24th, 2007 at 2:13 pm
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.
May 18th, 2007 at 6:25 pm
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.
Reuben
August 7th, 2007 at 2:40 pm
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!
Dave.
August 7th, 2007 at 7:54 pm
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’.
August 8th, 2007 at 2:13 pm
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.
December 3rd, 2007 at 9:01 am
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!
April 21st, 2008 at 4:23 am
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?
June 13th, 2008 at 5:35 am
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:
http://www.example.com/“>
and my regular expression in GA is:
/image/clicks/
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.
Thanks
.G.