Google Analytics – How To Use Custom Variables

By July 16, 2012 Analytics No Comments


Having learned a lot at Google Engage’s Advanced Analytics seminar last week, we’re keen to write it all down, to make sure that others can discover these underutilised features of Google Analytics. First stop, Custom Variables.


So, what are Custom Variables?


Custom variables help you with that very important aspect of data analysis – segmentation. Using custom variables, you can segment the behaviour of users on your site depending on a range of characteristics. Just a few examples might be;

– Visitors who viewed video.

– Visitors who are logged in

– Visitors interested in certain content (e.g. cooking category of pages)


You can make custom variables at 3 levels;

  1.  Visitors – e.g. what country are they from? Are they a subscriber?
  2. Visits – e.g. visits including a blog view, or visits including a video view
  3. Pages – e.g. when they saw a particular page of the blog, or content category.


The only thing you need to remember is that custom variables either have to be things about the page they visit (e.g. the content category or a subscriber page) or something they tell you (e.g. their location, gender, or language). Custom Variables aren’t some magic Google Analytics feature which can give you additional information about your visitors – YOU have to assign custom variables to visitors, so you need to know those things about them already.


How Do Custom Variables Work?


To make these custom variables work, Google Analytics puts a cookie on a visitors browser to allocate a custom variable to them. However, there are limits to how many custom variables you can use in a single request.


The sum of all your custom variables cannot exceed 5 in any given request

– A Visitor level metric occupies a whole slot for 2 years
–  A visit level metric occupies a slot for just one whole visit
– A pageview only uses more than one slot if you want to do more than one custom variable on one page


The code will look like this




Index = Slot and has to be a number between 1 and 5

Name is a string, e.g. “gender” or “video view”

Value is also a string, e.g. “male”, “yes” or “no

Opt_scope is the level of the variable (where visitor =1, visit =2, page =3).


If the viewing of the page itself results in the custom variable being assigned then the code needs to be put between _setAccount and _trackPageview.


If the visitor has to do something on the page to have a custom variable attributed (e.g. choose a language), then you must attach the code to visitor action, like onClick events.


For more information on how to use the code, visit the Google Developers page.


Tips for Custom Variables


– Before implementing custom variables, check for old ones.


– If you have complex tracking requirements, where you have a mix of page- and session-level variables that might collide, you should build a slot matrix to ensure that session-level variables do not inadvertently over-ride page-level variables.


– Similar to when you use Google Analytics event tracking or URL building – name things sensibly, so that in the future it is a system which is easy for other people to understand, and you also need to make sure there is no duplication of any of the names.


One New Idea To Help Achieve Your Sales Goals REQUEST YOUR FREE SPARK