This Cyber Monday Envato Tuts+ courses will be reduced to just $3. Don't miss out.
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.
What are Custom Variables?
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.
So How do Custom Variables Work?
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:
- page-level – this is the lowest level used to monitor particular ways in which the visitor interacts with the web page (e.g. AJAX, watching a video etc.)
- session-level – a label attached to this level is added to the actions of the visitor throughout the session, and is deleted when the session cookie expires.
- visitor-level – this is the highest level; the label is permanent and remains detached during subsequent visits until the visitor deletes the cookie or overwrites the value.
How Do I Configure Custom Variables?
Custom variables are quite easy to configure; you only need to add one line of code before the
_gaq.push(['._setCustomVar,INDEX, NAME, VALUE, OPT_SCOPE']);
- INDEX (required) – determines a slot for a custom variable in Google Analytics. There are 5 slots available, numbered 1 to 5. You should remember that, if the variables are to function correctly, a single variable must be placed in a single slot.
- NAME (required) – is the name of the variable that is going to appear in the report of the Google Analytics panel – Custom Variables
VALUE (optional) – is the actual value of the variable which is paired with
NAME. Any number of such value pairs is possible, for instance if
VALUEcan, one by one, equal the values of US, GB, PL etc.
- OPT_SCOPE (optional) – is a level within which a custom variable functions. As I described above, there are three levels: 1 (visitor-level), 2 (session-level), 3 (page-level). When this parameter is not provided, it is replaced with the default page-level.
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 ]);
But What Follows?
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:
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
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.
It's Worth Remembering...
- Don't duplicate the names of custom variables between the slots.
- Set custom variables before the pageview call.
- You cannot use more than five custom variables in a single request.
- Consider event tracking instead of custom variables for some demands, as then no additional (false) pageviews are generated in the panel.
- You can determine whether custom variables work by observing requests within Firebug, or with the help of the Chrome extension, Google Analytics Tracking Code Debugger.
This is Only the Beginning
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.