Mobile app version of vmapp.org
Login or Join
Martha676

: 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

@Martha676

Posted in: #GoogleAnalytics #Javascript

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Martha676

2 Comments

Sorted by latest first Latest Oldest Best

 

@YK1175434

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.

10% popularity Vote Up Vote Down


 

@Sue5673885

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme