自定义变量未在GA仪表板中跟踪

时间:2012-08-09 11:44:15

标签: google-analytics

我在我的javascript中使用自定义变量,所有页面都可以访问这些变量,下面是我在最后一个名为index.html的页面中的结束标记之前的GA跟踪代码。

        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跟踪对我来说很好。 到目前为止,我只能跟踪一个自定义变量,该变量已在名为country的head部分的主跟踪代码中定义(如上所示)。

我在javascript文件中使用的其他自定义变量(此js始终可在index.html中访问)似乎根本没有被调用。这个js文件包含不同自定义变量的不同_gaq.push命令,如下所示。

_gaq.push(['_ setCustomVar',5,'Page','app / index.html#portfolioDetailPage']);

问题:为什么我无法在GA中跟踪这些自定义变量,这与我在主跟踪代码中传递的“country”自定义变量不同? 我需要在每个_gaq.push之后传递_gaq.push(['_ trackPageview'])自定义变量声明吗?

任何人都可以建议,我一团糟:(

由于

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

谢谢Eduardo。我可能输错了我实际上正在使用正确的代码。我使用自定义变量进行跟踪,而在我的场景中,事件跟踪更有意义。

if(_gaq)_gaq.push(['_ trackEvent','Page','Home_Page_Landing','app / index.html']);

由于

相关问题