Real Implementation of Custom Variables in Classic Google Analytics
Many technical blogs dedicated to custom variables exist out there. But the sad reality is that the high majority of those blogs present custom variables as a simple snippet taken out of context. As a consequence, the real customisation/ implementation of custom variables becomes more than challenging for many developers, to say the least.
Thus, the primary objective of this article is to bridge that gap, complement and present with clear examples, with a context, how to really customise and implement custom variables in classic Google Analytics.
Primarily, as it is often presented, here is the normal Async GA code snippet:
_gaq.push([‘_setCustomVar’, index, name, value, scope]);
Hypothetically, let’s assume that you are an analyst or a developer for the Guardian.com
Let’s say that you are tasked to implement the classic Google Analytics on your site. Your first and trivial job will be to paste into all Guardian’s pages, the Google Analytics tracking code. That code should look like this:
var _gaq = _gaq || ;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’); s.parentNode.insertBefore(ga, s);
Let’s assume also that your boss has read the following blog post of Cutroni; and now, you are tasked to implement his new features: “Custom Variables”