GA中的事件跟踪未触发

LDJ*_*LDJ 9 google-analytics event-tracking

我已经将以下代码添加到我的JS中以跟踪按钮点击:

_gaq.push(['_trackEvent', 'category', 'action', 'label']);
Run Code Online (Sandbox Code Playgroud)

我使用Chrome开发工具打了一个断点,_gaq肯定会解析为GA对象,我甚至可以进入GA.js代码中的(缩小的)推送事件.然而,即使这没有错误,我也没有看到Fiddler/firebug/Chrome中记录任何GET或POST,也没有记录我的分析.正常页面分析对我来说很好,跟随在页面底部运行:

<script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'XXXXXXXXX']);
        _gaq.push(['_setDomainName', '.Domain.com']);
        _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);
        })();
    </script>
Run Code Online (Sandbox Code Playgroud)

任何人都有任何想法为什么上述代码不起作用?

bsk*_*ard 0

据我了解,您在外部 .js 文件中有 trackevent,并且在 -tag 底部调用了标准脚本<body>

明显的解决方案是移动脚本:

<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'XXXXXXXXX']);
    _gaq.push(['_setDomainName', '.Domain.com']);
    _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);
    })();
</script>
Run Code Online (Sandbox Code Playgroud)

在 -tag 中<head>,并调用此代码段下方的外部 js 文件。

喜欢:

<html>
<head>
    <script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'XXXXXXXXX']);
            _gaq.push(['_setDomainName', '.Domain.com']);
            _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);
            })();
    </script>   
    <script type="text/javascript" src="ext.js"></script>
</head>
<body>

</body>
Run Code Online (Sandbox Code Playgroud)