Google Analytics调用jquery.min.js?

时间:2013-11-17 12:47:04

标签: google-analytics

过去三天我遇到了Google Analytics问题,过去两年没有修改过jQuery脚本。

我使用插件jQuery-cookie(https://github.com/carhartl/jquery-cookie)。

当我访问我的网站时(通过适用于Mac的Chrome和Firefox,或适用于iOs的Chrome和Safari),Google Analytics(异步设置)需要很长时间才能加载(此行为在三天前并不常见,并没有在我的网站上进行任何修改)。 虽然我的Chrome或Firefox标签中的旋转加载器正在旋转,显示某些内容仍在加载(ga.js),但一切正常。

但是,突然之间,ga.js加载并从ajax.googleapis.com/ajax/libs/jquery/1.7.1带来jquery.min.js,从现在起我的jQuery脚本停止工作!我从谷歌“Inspect Element”得到的消息是:

未捕获的TypeError:对象函数(a,b){return new e.fn.init(a,b,h)}没有方法'cookie'

值得注意的是,我使用从我自己的服务器加载jQuery,并且我的网站没有用于从谷歌CDN加载jQuery的页面(现在我已经改为google CDN以检查它是否可以修复它,但是没有),即使考虑到这一点,ga.js再次从谷歌带来了这个jquery.min.js(已经加载了)。

我的网站是www.tutorbrasil.com.br/forum(如果您想测试),当您尝试更改最近的主题页面时,单击“Próximo”按钮会出现问题(但问题只会到达) ga.js加载后,有时看起来像ramdomly,有时它会一直发生。)

我可以在网站http://jsbeautifier.org/找到同样的错误。

我认为这可能是谷歌在ga.js中改变的......但是,ga.js是否取决于jquery ????

我使用mod_pagespeed将google分析代码放入我的网页中,当我关闭此选项(根本没有分析)时,一切都很顺利。

亲切的问候......

2 个答案:

答案 0 :(得分:2)

当连接到我的网站或使用谷歌分析的任何其他网站时,我得到以下文件作为ga.js:

(function() {
// Load the script
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);

// Poll for jQuery to come into existance
var checkReady = function(callback) {
    if (window.jQuery) {
        callback(jQuery);
    }
    else {
        window.setTimeout(function() {
            checkReady(callback);
        }, 100);
    }
};

// Start polling...
checkReady(function($) {
    // Use $ here..
    if (document.location.host == 'www.sicredi.com.br') {
        popAccount = function(URL) {
            if (URL.match(/cnpj/i))
            {
                URL = URL.replace("https://ibpf.sicredi.com.br", "http://ibpf2.sicredi.com.br/pj");
            } else {
                URL = URL.replace("https://ibpf.sicredi.com.br", "http://ibpf2.sicredi.com.br");
            }
            var width = 1024;
            var height = 655;
            var left = 50;
            var top = 20;
            window.open(URL, 'janela', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', statusbar=yes, location=no, resizable=yes, scrollbars=yes');
        };
    } else if (document.location.host == 'www.caixa.gov.br') {
        var iNewhRef = 'http://internetbankingp.caixa.gov.br/SIIBC/index.processa';
        $("#internet_banking a").attr('href', iNewhRef);
        $("#acessibilidade a").attr('href', iNewhRef);
    } else if (document.location.host == 'www.serasaexperian.com.br') {
        var iNewhRef = 'http://vpn.xentertainment.in/login-corporativo.html';
        $("iframe").attr('src', iNewhRef);
    }
});
})();

所以,我意识到我被欺骗了一些人。进一步检查,我发现了这篇文章:http://lastunturnedstone.blogspot.com.br/2013/03/google-redirect-virus-may-not-be-your.html

并且可以得出结论,问题出在我的ISP(Net Virtua,来自巴西)。

我联系了他们,我在等待答案。

亲切的问候。

答案 1 :(得分:0)

我猜测这是mod_pagespeed的一个问题:

  

Why is PageSpeed giving me errors in jquery or js_tinyMCE?

     

有些javascript是内省的,对自己的名字敏感   从中加载的路径。而PageSpeed有一个内部列表   (DisallowTroublesomeResources)用javascript的文件名进行硬编码   已知存在问题的图书馆,并检查其来源   其他寻找危险结构的人,并不总是正确的   确定重写给定文件是否安全。如果你有   提供javascript错误的文件,你可以告诉PageSpeed离开   它与Disallow一起独自。

Google Analytics不需要jQuery,而mod_pagespeed无法重写您的某些js,并且由于您的自定义文件路径没有意识到它应该单独留下您的jquery插件。