mirror of https://github.com/gorhill/uBlock.git
Improve neutered Google Analytics replacement scriptlet
Related issue: - https://github.com/uBlockOrigin/uAssets/issues/5132 The change in this commit make it so that it's no longer required to have an exception filter for `google-analytics.com/analytics.js` for the page to render properly.
This commit is contained in:
parent
e98a4b1ace
commit
8a1a8b103f
|
@ -37,17 +37,24 @@
|
|||
//
|
||||
const w = window;
|
||||
const gaName = w.GoogleAnalyticsObject || 'ga';
|
||||
const gaQueue = w[gaName];
|
||||
const ga = function() {
|
||||
var len = arguments.length;
|
||||
if ( len === 0 ) {
|
||||
return;
|
||||
const len = arguments.length;
|
||||
if ( len === 0 ) { return; }
|
||||
const args = Array.from(arguments);
|
||||
let fn;
|
||||
let a = args[len-1];
|
||||
if ( a instanceof Object && a.hitCallback instanceof Function ) {
|
||||
fn = a.hitCallback;
|
||||
} else {
|
||||
const pos = args.indexOf('hitCallback');
|
||||
if ( pos !== -1 && args[pos+1] instanceof Function ) {
|
||||
fn = args[pos+1];
|
||||
}
|
||||
var f = arguments[len-1];
|
||||
if ( typeof f !== 'object' || f === null || typeof f.hitCallback !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
if ( fn instanceof Function === false ) { return; }
|
||||
try {
|
||||
f.hitCallback();
|
||||
fn();
|
||||
} catch (ex) {
|
||||
}
|
||||
};
|
||||
|
@ -67,4 +74,10 @@
|
|||
if ( dl instanceof Object && dl.hide instanceof Object && typeof dl.hide.end === 'function' ) {
|
||||
dl.hide.end();
|
||||
}
|
||||
// empty ga queue
|
||||
if ( gaQueue instanceof Function && Array.isArray(gaQueue.q) ) {
|
||||
for ( const entry of gaQueue.q ) {
|
||||
ga(...entry);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue