From 30c38de9bc9d6e7d4502a5c627aa4b3a63b612bf Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 13 Oct 2020 18:53:11 -0400 Subject: [PATCH] Fix local Google Analytics replacement script Related issue: - https://github.com/uBlockOrigin/uAssets/pull/4115 --- src/web_accessible_resources/google-analytics_analytics.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/web_accessible_resources/google-analytics_analytics.js b/src/web_accessible_resources/google-analytics_analytics.js index 5d6a087c8..87704a282 100644 --- a/src/web_accessible_resources/google-analytics_analytics.js +++ b/src/web_accessible_resources/google-analytics_analytics.js @@ -38,6 +38,7 @@ const w = window; const gaName = w.GoogleAnalyticsObject || 'ga'; const gaQueue = w[gaName]; + // https://github.com/uBlockOrigin/uAssets/pull/4115 const ga = function() { const len = arguments.length; if ( len === 0 ) { return; } @@ -46,6 +47,8 @@ let a = args[len-1]; if ( a instanceof Object && a.hitCallback instanceof Function ) { fn = a.hitCallback; + } else if ( a instanceof Function ) { + fn = ( ) => { a(ga.create()); }; } else { const pos = args.indexOf('hitCallback'); if ( pos !== -1 && args[pos+1] instanceof Function ) { @@ -54,7 +57,7 @@ } if ( fn instanceof Function === false ) { return; } try { - fn(); + setTimeout(fn, 1); } catch (ex) { } };