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?

link|improve this question
feedback

2 Answers

up vote 5 down vote accepted

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.

link|improve this answer
feedback

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".

link|improve this answer
Thanks. I'll give that a try and report back once there's been time for the data to hit Google Analytics. – Will Martin May 9 '11 at 15:35
1  
@Will Martin you can use Google Analytics Debug to test it out manually. I did so, and setting it to "0" instead of 0 works, though for non-zero numbers, it'll cast them to a string without trouble. chrome.google.com/webstore/detail/… – yahelc May 9 '11 at 15:41
@yc01 Good tip, +1. I tried it out with "none" as the default value, and it works fine. Thanks to you and @paulmorriss. – Will Martin May 9 '11 at 15:54
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.