_setVar
仍作品,但你应该使用_setCustomVar
来代替,因为它更强大。
这是你的旧的代码看起来像使用异步代码:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setVar', 'memberlevel-2']);
_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);
})();
要使用setCustomVar相反,你可以这样做:
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setCustomVar', 1, 'memberlevel', '2', 3]);// page-level scope (3), in slot #1
_gaq.push(['_trackPageview']);
要小心,因为_setVar'的'范围和'_setCustomVar'是不同的。例如,默认情况下'_setVar'设置一个持久的用户级变量,适合于在登录后设置用户的成员级别。 '_setCustomVar'默认为页面级范围(3),这对跟踪单个页面(类别等)的附加属性更好。如果切换到'_setCustomVar',则应为第四个参数指定1(用户级作用域)。更多信息:https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables – 2012-10-16 07:17:39