mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 17:41:03 +01:00
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
1 changed files with 21 additions and 8 deletions
|
@ -37,17 +37,24 @@
|
||||||
//
|
//
|
||||||
const w = window;
|
const w = window;
|
||||||
const gaName = w.GoogleAnalyticsObject || 'ga';
|
const gaName = w.GoogleAnalyticsObject || 'ga';
|
||||||
|
const gaQueue = w[gaName];
|
||||||
const ga = function() {
|
const ga = function() {
|
||||||
var len = arguments.length;
|
const len = arguments.length;
|
||||||
if ( len === 0 ) {
|
if ( len === 0 ) { return; }
|
||||||
return;
|
const args = Array.from(arguments);
|
||||||
}
|
let fn;
|
||||||
var f = arguments[len-1];
|
let a = args[len-1];
|
||||||
if ( typeof f !== 'object' || f === null || typeof f.hitCallback !== 'function' ) {
|
if ( a instanceof Object && a.hitCallback instanceof Function ) {
|
||||||
return;
|
fn = a.hitCallback;
|
||||||
|
} else {
|
||||||
|
const pos = args.indexOf('hitCallback');
|
||||||
|
if ( pos !== -1 && args[pos+1] instanceof Function ) {
|
||||||
|
fn = args[pos+1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if ( fn instanceof Function === false ) { return; }
|
||||||
try {
|
try {
|
||||||
f.hitCallback();
|
fn();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -67,4 +74,10 @@
|
||||||
if ( dl instanceof Object && dl.hide instanceof Object && typeof dl.hide.end === 'function' ) {
|
if ( dl instanceof Object && dl.hide instanceof Object && typeof dl.hide.end === 'function' ) {
|
||||||
dl.hide.end();
|
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 a new issue