Using Custom Variables in Google Analytics – why and how

NetBooster Employee
article

Using Custom Variables in Google Analytics – why and how


Google Analytics has many metrics that can help drive insights for your website but it cannot cover every business type – there will be circumstances your website covers that cannot be catered for by the standard metrics or dimensions.

This is where custom variables come in – they are spare slots GA has supplied for you to tailor the GA reports to your business. These five slots are yours to measure anything you wish! If you need more than 5, Google Analytics Premium supports up to 50 custom varaibles - we are official resellers of Google Analytics Premium so please do get in touch.

The use of these variables is usually a sign of a more advanced web analytics policy: you’ve got the standard tracking installed on your website, set up a few goals and ecommerce and have started to generate reports that inspire action not data-puking – great job! But now you are starting to ask your web analytics questions whose answers can’t be covered by the standard installation.

Custom variables are distinct from Event tracking or virtual page views but often work hand in hand with them to help create useful reports. They are used when you need to “tag” certain user behaviour – a typical use is to track logged in users, or perhaps you want to know if a user is a 'Return Customer' rather than the standard GA dimension of Returning Visitor. Once you have tagged users using custom variables you can then apply custom segments and create reports displaying this bespoke information.

Custom variables in Google Analytics come in three flavours, which correspond to how “sticky” the variable is on a user – choosing this level of stickiness helps determine what they can measure:

The three flavours are “Visitor Level”, “Session Level” and “Page Level”:

Visitor Level Custom Variables

These are the stickiest – any user who has this variable applied to them will keep it in their GA cookies across multiple sessions. A common use of these is for returning customers, or perhaps if they have viewed a certain page which you want to keep track of over user sessions.

Any data you are looking to keep over repeat visits is applicable. With the increased social data available, demographic data of your users can become available (although respect GA's terms of service to not record personal information about a user). If say, you know a user is female or male from a form they have filled in on your website, or through Facebook's social graph data, that data can be pushed into your Google Analytics reports to give you reports such as conversion rates between the sexes. Useful for dating websites and beyond!

Another use may be for how a user first found your website - even with Multi-touch funnels this information will only be available for 30 days. Placing a users original source in a visitor level custom variable will mean you can work on first touch attribution analysis rather than the normal last touch.

Finally, since visitor level custom variables are stored in visitor cookies, it is possible to read this information and customise the content of your website accordingly. If say, a user is a common visitor you could show them their most viewed but not yet bought products and skip content designed to attract new customers. This can have powerful conversion rate benefits.

Session Level Custom Variables

These are not so sticky, but still stickier than Page Level – they last from when they are set until a user stops browsing your website (their session ends). If a user revisits your website, they will have to have this variable reset for it to appear against their visit. A common use for these is to track users who log in to your website – you don’t need to know they once logged in a few sessions ago, but only if they log in that particular sessions - therefore a visitor level variable would be inappropriate.

Other uses include tracking the way a user has interacted with the site - did they use your shopping basket this session? Did they view that product video before they bought? Any key content on the website that is there to drive conversions can be easily accessed.

Page Level Custom Variables

These are custom variables that will only last on a per page basis – they are the least sticky. Once a user leaves that page, they will not have this variable set anymore.

They can be useful to help improve the navigation of your reports – if your website has very messy URLs with no folder structure, for example, you could use page level variables to record where a user is in your website (i.e. set the Custom variable to “About Us” or “Office finder”). Or, if on a large content website, a page level variable can be used to track which category a user is in, or perhaps which journalists work - this way it is possible to see at a glance how popular that author or category is - you need only go to your custom variable report and see how many hits that category got.

Page level variables can also be used to track interactions on the page, so if you have event tracking on your external links a custom variable can be set to track if the link was in the header, sidebar or footer of your webpage.

Or perhaps you want to track how many times a user has had an error on a critical webform - how many times did it come up with "Please fill in your postcode?" This can be great for conversion rate analysis.

Mixing up types of custom variables - visitor/session, session/page, etc.

Another good use of custom variables is to use the interplay between the types to create insights.

For instance, do users who have log in once always log in? Or do they only log in every so often? With the combination of session level to track a login session and visitor level to track the number of sessions they log in, these questions can be answered.

Another example if using a Return Custom tracking at visitor level is to use it to record the last product bought, then a session level variable to track if they use a post-sales support section of the website, giving the ability to see which products are generating the most activity even if a user does not get in direct contact. Is your post-sales content enough to satisfy users?

Implementation of Custom Variables

Using custom variables opens up a world of possibilities - quite often the main barrier to their use is knowing what you need to measure rather than their implementation. There are good help files available for the implementation but in brief it just involves setting them via calls such as:

_setCustomVar(index, name, value, opt_scope)

The parameters in the script point to:

  • index - 1 to 5 - you only get five in normal GA
  • name - anything you like to identify the type of dimension in the reports, but bear in mind a 64 character limit for name and value
  • value - The state of the named parameter - i.e. if you have set name to "Log in status" then value could take "Logged In" or "Logged Out"
  • opt_scope - the "stickiness" of the parameter as shown above - 1=visitor level, 2=session level and 3=page level

When setting the variables, make sure they are done before the data is sent to GA via _trackPageview, else the data may not be recorded.

An example then, for a logged in user would be to call this on a successful log in:

_setCustomVar(1, "Log in status", "Logged In", 2)

This would set in slot 1 a session level custom variable that the user has logged in that session. Once data had been gathered, you could then create advanced segments just for these users, and see how they interact with your site in isolation from non-logged in users.

Conclusions

Custom variables are a great phase two operation to your Google Analytics set up and really start to develop the power of the platform giving it capabilities competitive with other paid for enterprise packages and with relative ease of set up. The only real barrier is scoping out and planning which ones will give you the reports you need.

If the five slots offered in the free version are not enough for your needs, do remember that as resellers of Google Analytics Premium, we can help extend this feature to 50 custom variables, for truly bespoke web analytics reporting in a familiar setup.