我在我的javascript中使用了自定义变量,所有页面都可以访问,下面是我的GA跟踪代码,它紧跟在唯一一个名为index.html的页面中关闭的head标记之前。
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33766550-1']);
var currentCountry = 'N/A';
if (localStorage.getItem('country')) {
currentCountry = localStorage.getItem('country');
}
_gaq.push(['_setCustomVar', 1, 'Country', currentCountry]);
_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);
})();GA跟踪对我来说工作得很好。到目前为止,我只能跟踪一个在主跟踪代码中定义的自定义变量,该变量位于head部分中的country(如上所示)。
我在javascript文件中使用的其他自定义变量(这个js在index.html中总是可以访问的)似乎根本没有被调用。此js文件包含针对不同自定义变量的不同_gaq.push命令,如下所示。
_gaq.push('_setCustomVar',5,‘页面’,'app/index.html#portfolioDetailPage');
问:为什么我不能在GA中跟踪这些自定义变量,这与我在主跟踪代码中传递的“country”自定义变量不同?我需要在自定义变量声明的每个_gaq.push后面传递_gaq.push('_trackPageview')吗?
有没有人可以建议一下,我现在很乱:
谢谢
发布于 2012-08-11 22:28:27
谢谢爱德华多。我可能打错了,实际上我用的是正确的代码。我使用自定义变量进行跟踪,而在我的场景中,事件跟踪更有意义。
if(_gaq) _gaq.push('_trackEvent','Page','Home_Page_Landing','app/index.html');
谢谢
发布于 2012-08-10 09:40:37
https://stackoverflow.com/questions/11882690
复制相似问题