I am using custom variables in my javascript that is accessible to all the pages and below is my GA tracking code immediately preceding the closing head tag in the only page called index.html.
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33766550-1']);
var currentCountry = 'N/A';
if (localStorage.getItem('country')) {
currentCountry = localStorage.getItem('country');
}
_gaq.push(['_setCustomVar', 1, 'Country', currentCountry]);
_gaq.push(['_trackPageview']);
(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);
})();
The GA tracking is working fine for me.
I have so far been able to track only one custom variable that has been defined in the main tracking code in the head section called country(as shown above).
The rest of the custom variables that I have used in the javascript file(this js is always accessible in index.html) seems to be not getting called at all. This js file contains the different _gaq.push commands for the different custom variables, as shown below.
_gaq.push([‘_setCustomVar’, 5, ‘Page’, ‘app/index.html#portfolioDetailPage’]);
Question: Why am I not been able to track these custom variables in the GA unlike the ‘country’ custom variable I passed in the main tracking code?
Do i need to pass _gaq.push([‘_trackPageview’]) after each of the _gaq.push for custom variables declarations?
Can anybody please suggest, I am in a big mess 🙁
Thanks
Thanks Eduardo. I might of typed it wrong I am actually using the correct code. I was using custom variables for tracking whereas in my scenario event tracking made more sense.
if(_gaq) _gaq.push([‘_trackEvent’, ‘Page’, ‘Home_Page_Landing’, ‘app/index.html’]);
Thanks