Thursday, 21 April 2011 14:40
Familiarity with your users and their needs is the most important aspect of any successful site or web campaign. Google Analytics is the perfect tool to gather this sort of information. But there’s much more you can find out about your users when you begin using custom variables to make better decisions.
Using custom variables carries huge potential, as it allows you to acquire information about the behavior of your visitors.
You can treat custom variables as your own extension of metrics and dimensions. These provide you with the ability to gather non-standard and detailed data, which are not available via the Google Analytics panel.
Using custom variables carries huge potential, as it allows you to acquire information about the behavior of your visitors, which, in total, can significantly contribute to an increase of the ROI (return on investment) of the website or e-shop.
For example, using custom variables makes it possible to differentiate the activities of the logged in users versus those who never signed in. This provides an opportunity to observe the behavior of the website designed for a particular target group. For instance, we can learn which page of our website is the one that males – aged between 20 and 30 – visit most frequently. And this is just a tiny piece of the information that can be stored with the help of custom variables.
The functionality of custom variables is wonderful in its simplicity. In fact, it’s based on the simple fact that, while performing a pre-defined activity, the user is labeled and the information about this label is subsequently stored in a cookie. Then, on the basis of this particular label, we can create a new section in the statistics of the Google Analytics panel.
Custom variables can be used in one of three ways:
Custom variables are quite easy to configure; you only need to add one line of code before the _trackPageview call.
_gaq.push(['._setCustomVar,INDEX, NAME, VALUE, OPT_SCOPE']);
NAME. Any number of such value pairs is possible, for instance if NAME=country, VALUE can, one by one, equal the values of US, GB, PL etc.
var _gaq = _gaq || [];
_gaq.push(['_setAccount','UA-xxxxxxxx-x']);
_gaq.push(['._setCustomVar,INDEX, NAME, VALUE, OPT_SCOPE']);
_gaq.push(['_trackPageview']);
Now, let’s review how custom variables function in practice. Let’s suppose that we want to keep track of the visitors of our website’s – distinguishing between those who did and did not log in. In order to do so, before the _trackPageview call, we insert code describing the user.
_gaq.push(['._setCustomVar, 1, // first slot 'user-type', // custom variable name 'visitor', // custom variable value 2 // custom variable scope - session-level ]);
Once the visitor logs into your website, we change this code, accordingly:
_gaq.push(['._setCustomVar, 1, // first slot 'user-type', // custom variable name 'regular-user', // custom variable value 2 // custom variable scope - session-level ]);
It’s time to present the results of the described script. After the script had been executing for a week, an advanced segment in Google Analytics panel was created. Its aim is to divide the data in the panel into: total, report for logged-in users, and report for users who didn’t log in for particular metrics.
The segment itself is created through Advanced Segments => Create a new advanced segment. Then you should set the dimensions according to the screenshot below:

The variable which we defined using JavaScript was in the first slot, so we have to select Key 1 and Value 1. Then, we set the key which we are interested in (user-type), and the value for the defined key (visitor) together using concatenation. Next, we name and test the advanced segment. The number of visits during a particular period of time for particular segments will be calculated within the test.
We define the second segment which takes into account the logged-in users in the same way. We can create it by analogy with the pattern presented above – with the difference in that the custom variable is set as regular-user.
After establishing the two segments, we can activate them. The result is presented below. Such a set of data is a great basis for an in-depth analysis of the activities on a webpage.

Using custom variables translates into more justified and accurate site decisions.
The example presented in this article only illustrate the process of using a single custom variable, and determining the best way to manage a website, according to the type of visitor. Of course, this is only the beginning. Custom variables can become incredibly powerful when we combine several of them at the same time. As a quick example, with the applicable data from a website’s registration process, we can then track, not only the sex of the visitor (session-level), but also his or her age bracket (session-level). Further, we could divide the visitors into groups who have made purchases in our fictional eShop, or even track those who took a specific action, such as clicking on a Facebook button.
These techniques translate into more justified and accurate site decisions.