I am trying to fire a custom varible to Google Analytics on Click. I have a web page which has different languages and my client wants to have a custom varable record these when clicked. (The click just hides and shows divs). The page does not re-load. I suggested that the best solution would be to track events, however they do not want this solution.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21556445-2']);
_gaq.push(['_trackPageview', '/fpc/e-brochure-circle']);
_gaq.push(['_setAllowLinker', true]);
$('.lang').live('click', function (event, ui) {
try {
var language = $(this).attr('data-language');
_gaq.push(['_setCustomVar', 5, 'content_language', '' + language + '', 3]); // change language value accordingly
_gaq.push(['_trackPageview', '/fpc/e-brochure-circle']);
} catch (err) { }
});
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
Is it possible to fire the custom varable more than once on the same page. Using Firebug I can see that the code is working and the language is being put in correctly. It just will not show up in Google Analytics.
Any help on getting this working will be great.
Many thanks Steve