Skip to content

Commit

Permalink
Improve google-analytics shim
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 24, 2022
1 parent 250cf96 commit fba680f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/web_accessible_resources/google-analytics_analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,22 @@
if ( dl instanceof Object ) {
if ( dl.hide instanceof Object && typeof dl.hide.end === 'function' ) {
dl.hide.end();
dl.hide.end = ()=>{};
}
if ( typeof dl.push === 'function' ) {
const doCallback = function(item) {
if ( item instanceof Object === false ) { return; }
if ( typeof item.eventCallback !== 'function' ) { return; }
setTimeout(item.eventCallback, 1);
item.eventCallback = ()=>{};
};
dl.push = new Proxy(dl.push, {
apply: function(target, thisArg, args) {
doCallback(args[0]);
return Reflect.apply(target, thisArg, args);
}
});
if ( Array.isArray(dl) ) {
dl.push = item => doCallback(item);
const q = dl.slice();
for ( const item of q ) {
doCallback(item);
Expand Down

0 comments on commit fba680f

Please sign in to comment.