Though it’s not indicated anywhere in the interface, the table filter field in Google Analytics reports is interpreted as a regular expression (or “regex” for short).
In regex notation, there are two types of characters: literal characters and metacharacters. If you’re trying to filter your Pages report to display pages that contain article.aspx?id=, you must “escape” the question mark with a \ character so the ? acts as a literal character. Otherwise, the ? will be interpreted as metacharacter – specifically, a quantifier meaning zero or one of the previous character.
To further illustrate, if you enter article.aspx?id= into the filter field, you’ll match any pages that contain article.aspid= or article.aspxid=, but not article.aspx?id=, since the question mark is interpreted as a regular expression metacharacter and not as a literal. If you enter article.aspx\?id= into the filter field, you’ll match any page that contains article.aspx?id= since the question mark is now interpreted literally.
By escaping the question mark, we “escape” interpretation of the character following the \ as a regex metacharacter and allow it to act as a literal character.
Note as well that in proper regex notation, all literal . characters are also escaped so they’re not interpreted as the wildcard metacharacter that matches any single literal character. The filter article.aspx\?id= would also match pages that contained articlesaspx?id= and article-aspx?id= because the . is acting as a metacharacter. To restrict the match to article.aspx\?id=, you’d need to also escape the . as in article\.aspx\?id= and thereby force the . to be interpreted literally.
Don’t feel that you need to memorize regular expression notations. Know the principles, and download a cheat sheet at: http://www.e-nor.com/blog/google-analytics/google-analytics-regex-and-keyboard-shortcuts-desktop-backgrounds
view at full size
The Google Analytics IP range tool can help you set up an IP address filter for your profiles.
As a best practice, your Google Analytics profiles should not display activity on your company’s website that originated from within your company. To exclude this traffic, you can apply a profile filter based on IP address.
Since many organizations access the Internet through an allocated IP address range, Google Analytics has provided an IP address range tool that you can use to express an IP range as a single regular expression. You can ask your IT folks for the lower and upper bounds of your IP range, plug them into the tool, and then use the resulting regex as the Filter Pattern in your Exclude > IP Address profile filter.
Two types of profiles that you should not apply this filter to are those that you are using for your development websites, since you’ll probably want to track internal activity there for testing purposes, and also your raw profile, which you should always maintain without any filters.
Filtering activity from a single computer (in your home, for example) may actually be a little trickier, since many “standalone” computers dynamically acquire different IP addresses each time they access the Internet. If you can determine that your IP address is static, you can also set up a profile filter based on your single, static IP address.
view at full size
You can test regular expressions for your goals directly in the Pages report.
In a recent post, we used a Regexpal to test a regular expression for a goal. For a straighforward additional check, you can apply the regular expression as an advanced filter within the Pages report and verify that all pages that should match the regex are in fact listed in the table.
This assumes, of course, that you’re not configuring a goal for completely new pages; these pageviews must have already occurred for the pages to appear in the report.
Please note that a Page value in a report-level table filter does not have the same effect as a Page value in an advanced segment. That is, as a report filter, the matches are limited to the pages that directly match the filter and do not extend to all other pageviews that occurred during the same visit, which is the case for an advanced segment based on Page.
view at full size
You can test your regular expressions with a tool such as Regexpal.
Regular expressions, or “regex”, can be very useful within Google Analyitcs, but regex syntax is quite challenging, even for the initiated. Before your deploy your regular expressions, you should take advantage of tools that are designed specifically for regex testing.
As a simple example, let’s say that you have individual signup forms for eight different product trials on your website, and that the request URI of each thank-you page is in the following format:
Let’s also say that you want to set up a single signup goal for products 2 and 7, which are closely related.
After consulting a regex cheat sheet, you test the following regular expression at regexpal.com:
Regexpal indicates a match, but when you also notice that it has highlighted the . character in the regex field, you realize that you have forgotten to “escape” the . character with a \ character to make it a literal . and not the regex notation for any single character. You just add \ before . to escape it.
Now you have a clean regular expression that will do its job for you as the Goal URL. (Just make sure that you select Regular Expression as your goal Match Type.)
view at full size
For multiple dimension values, use a single profile filter with the regex pipe symbol.
Let’s say that you manage a website that sells ski equipment and that you want to create a Google Analytics profile specifically for Australia and New Zealand. It might seem logical to apply two include filters: one for Australia and one for New Zealand. The problem is that the first include filter would irrevocably exclude all traffic that didn’t match the dimension value specified, so applying additional include filters for different values of that same dimension would be pointless.
Regular Expressions to the rescue!
To achieve our objective, we need only to apply a single profile filter that specifies both dimension values separated by the regex pipe symbol (|), which, very simply, means “or”.
In this way, we include both Australia and New Zealand with a single filter. You can use the pipe symbol for the same purpose in advanced segments and advanced table filters.
And if you’d like to create a more comprehensive filter for Southern Hemisphere ski spots, you can use the pipe symbol with multiple values:
Australia|New Zealand|Argentina|Chile|Brazil|South Africa
(As a note, skiing is actually available in all of these countries.)