<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-x']);
_gaq.push(['_setCustomVar(1,'landline','acct_Summary']);
_gaq.push(['_trackEvent','Telemedia','bill_guide']);
(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
In Google Analytics, I want to send some custom information to Google Analytics whenever user visits a particular page. I have used the above code but this does not works. Can anyone tell me what is problem here?
Your syntax for setting the custom variable is incorrect. You're trying to directly call a global function called setCustomVar that doesn't exist.
It should be:
_gaq.push(['_setCustomVar', 1,'landline','acct_Summary']);
You're not actually calling the _setCustomVar function here; since this is async code, you're just naming the function that will be called, and the parameters its receiving. When the GA code executes, it will call the function listed in the first parameter of that array, with the parameters defined in the latter parameters.
Worth noting that, with this current configuration, since you're not setting the final scope
parameter, it defaults to page-level. ie, it will only track that variable for that one page, and thus will not persist. If you want to change it to session level, set the value to 2; for visitor level, set it to 1.
精彩评论