_gaq.push不会发送数据

时间:2014-09-05 13:46:38

标签: javascript analytics

某种程度上我的_gaq.push功能无效。如果我设置debug = true我可以看到日志,我知道它会转到其他地方(当我有debug=false时),因为我尝试添加日志。这是我的代码

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_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);
})();

var debug = false;

function send_data(text, url) {
    if (debug) {
        console.log("_gaq.push(['_trackEvent', 'Site-change', " + text + ", " + url + "]);");
    } else {
        _gaq.push(['_trackEvent', 'Site-change', text, url]);
    }
}

$('.navigation .child a').unbind('click').on('click', function(e) {
    var url = $(this).attr('href');
    var text = $(this).text();
    send_data(text, url);
});

有什么想法吗?

0 个答案:

没有答案