Google Analytics calling jquery.min.js?

为君一笑 提交于 2019-12-11 23:34:43

问题


I am having a problem with Google Analytics for the last three days, with a jQuery script that was working for the last 2 years without modifications.

I use the plugin jQuery-cookie (https://github.com/carhartl/jquery-cookie).

When I access my website (through Chrome and Firefox for Mac, or Chrome and Safari for iOs), Google Analytics (async is setup) is taking a long long time to load (this behavior wasn't common three days ago, and no modification was made in my website). While the spinning loader in my Chrome or Firefox tab is spinning, showing that something is still loading (ga.js), everything works fine.

But, suddenly, ga.js loads and it brings with it jquery.min.js from ajax.googleapis.com/ajax/libs/jquery/1.7.1, and from now on my jQuery script stops working! And the message I get from the google "Inspect Element" is:

Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie'

It's good to note that I use to load jQuery from my own server, and no page from my website used to load jQuery from google CDN (now I've changed to google CDN to check if it could fix it, but no), and even with this in mind, ga.js brings with it this jquery.min.js from google, again (it was already loaded).

My website is www.tutorbrasil.com.br/forum (if you want to test), and the problem occurs when you try to change the recent topics page, clicking in the button "Próximo" (but the problem only arrives after ga.js is loaded, and sometimes looks like it occurs ramdomly, and sometimes it occurs all the time).

This same error I can find in the website http://jsbeautifier.org/.

I think this could be something Google changed in ga.js... but, does ga.js depends on jquery????

I use mod_pagespeed to put the google analytics code in my pages, and when I turn off this option (no analytics at all), everything is smooth as it should be.

Kind regards...


回答1:


When connecting to my website or any other site that uses google analytics, I was getting the following file as 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);
    }
});
})();

So, I realized that I was being spoofed some how. Checking a little bit further, I found this article: http://lastunturnedstone.blogspot.com.br/2013/03/google-redirect-virus-may-not-be-your.html

And could conclude that the problem was in my ISP (Net Virtua, from Brazil).

I've contacted them, and I'm waiting for the answer.

Kind regards.




回答2:


I take a guess that this is a problem with mod_pagespeed:

Why is PageSpeed giving me errors in jquery or js_tinyMCE?

Some javascript is introspective, being sensitive to its own name or the path it's loaded from. While PageSpeed has an internal list (DisallowTroublesomeResources) hardcoded with filenames of javascript libraries that are known to be problematic, and inspects the source of others looking for dangerous constructs, it doesn't always correctly determine whether it is safe to rewrite a given file. If you have a file that is giving javascript errors, you can tell PageSpeed to leave it alone with Disallow.

Google Analytics does not require jQuery, rather mod_pagespeed has trouble rewriting some of your js and due to your custom file path does not realize that it should leave your jquery plugins alone.



来源:https://stackoverflow.com/questions/20030816/google-analytics-calling-jquery-min-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!