Google Analytics: Advanced Filters Guide

Thought I’d share a post on how to use advanced filters in Google Analytics and what are some scenarios where they can come in handy.

Advanced filters are very useful for extracting information from available fields (i.e. campaign source, campaign term) using regular expressions and then using the extracted information to manipulate other fields in Google Analytics so that you can customise how data is recorded in your reports.

advanced-filters

First of all, before you use advanced filters, it is important that you have some kind of basic knowledge on regular expressions. If you don’t, then perhaps it’s a good idea to read up on what those cryptic symbols mean and how they’re very useful in pattern matching.

Once you’ve gotten a handle on some basic regular expressions, go to your filter manager and create a new filter. In filter type, select custom filter and then the advanced radio button. You will see three drop down menus with a text field next to each one of them. In the drop down menus, you will see a list of fields available in Google Analytics available for you to use.

Each advanced filter allows you to extract information from a maximum of 2 fields, field A and field B while allowing you to write information to a maximum of 1 field, the constructor.

Once you’ve selected a desired field to extract information from, you will need to enter the regular expression in the text field beside it. In your regular expressions, the parenthesis () is used to extract the matching parts of the field value and then storing these matches into variables. The variables $A and $B refer to fields and the numbers refer to the order of the parenthesis (i.e. $A3 corresponds to the 3rd parenthesis of field A’s matched regular expression.). These variables can then be accessed in the constructor to return the extracted value.

So let’s look at an example. Let’s say I wanted to append the category name based on the URL query string parameter to the page title because my CMS can’t seem to generate the category names in the page title and I can’t get any meaningful insights into which categories are popular from the content reports.

filter-example

In field A, I will choose Request URI and next to it, my regular expression (\?|&)cat=([^&])* which means extract the category value from the URL. This is stored in $A2 because the value I want is in the 2nd parenthesis.

In field B, I’ll just select everything because I want to append $A2 to whatever is already there. This is stored as $B1.

Then in the constructor, I’m telling Google Analytics to append the value in $A2 to the value in $B1. So if the category value extracted is ‘Shoes’ and my original page title is ‘Online Shopping’, then the modified page title will be ‘Online Shopping Shoes’. This should be reflected in the content reports.

I will need the request URI and page title field so I’ll make field A and B as required. By selecting yes for the override output field means that if that field already has a value, override it with the new value. Finally since this isn’t case sensitive, I’ll select no.

That’s pretty much it! I’ve written an example to append true searched terms to the keywords report so you can have a look at that example too.

Remember to always test filters in a test profile before applying it to your main profile.

2 Comments on "Google Analytics: Advanced Filters Guide"


  1. hi,

    how would i make sure that any url containing a bTag (banner tag) gets attributed to the original url?

    so, urls like: /page.php?btag=123njk34[&otherPossibleParams]
    /page.php?param1=kn3i24h&btag=abcdefg

    must canonicalise back to one record, namely, /page.php

    I tried, Output to -> $B – $A where A is finding everything after ?btag and $B is the entire URI

    Thanks,
    P

    Reply

    1. Hi Paul,

      You would probably use a search & replace filter instead. You can probably search for /page.php(.*) and replace with /page.php.

      This will tell GA to match anything after /page.php and just rewrite it all to /page.php, merging it into 1 record.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *