: Does Google Analytics allow custom variables to have a value of zero? I was interested in tracking the versions of QuickTime my users have installed. As suggested in an earlier question, I
I was interested in tracking the versions of QuickTime my users have installed. As suggested in an earlier question, I have set up a custom variable and built a report around it. Here is my code for the check:
function qt_check(){
var p = navigator.plugins;
var name, ver = 0;
for(i = 0; i < p.length; i++){
name = p[i].name;
if(name.indexOf("QuickTime Plug-in") !== -1){ ver = p[i].version; }
}
return ver;
}
pageTracker._setCustomVar(1, "QuickTime Version", qt_check(), 1);
As you can see, I set up the qt_check() function so that it would return a value of zero if the user does not have any version of QuickTime installed. My idea was that in addition to getting a readout on the various versions of QuickTime, I would be able to see how many people don't have it at all by looking for version "0".
But now that I have a few days of data, I find that although there have been 933 visits during that time, nobody registered as having QuickTime version 0.
Should I be passing some other value to Google Analytics? Is the 0 causing it to discard the variable?
More posts by @Martha676
2 Comments
Sorted by latest first Latest Oldest Best
Your problem is that 0 is a falsy value in JavaScript. So, any number EXCEPT zero will just be cast to a string if you pass it as a Number. But, since 0 evaluates as false, it gets interpreted that you're not passing a value for a required field, and the setCustomVar fails. So, yes, setting it to "0" instead of 0 will work.
The _setCustomVar function takes a string for a value and you're setting ver to a number 0. I think you need to set it to "0".
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.