From 8cd2a1d263a96421487b39040c1d23eb01169484 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 18 May 2021 11:08:20 -0400 Subject: [PATCH] Make googletagmanager_gtm.js an alias of google-analytics_analytics.js Related feedback: - https://ilakovac.com/teespring-ublock-issue/ The surrogate script googletagmanager_gtm.js was essentially a subset of surrogate script google-analytics_analytics.js. This commit makes it a plain alias so that the whole GA API -- often expected by clients of GTM -- is properly stubbed. --- src/js/redirect-engine.js | 10 +++++----- .../google-analytics_analytics.js | 13 +++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index f52b8fb87..377b561be 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -79,7 +79,11 @@ const redirectableResources = new Map([ data: 'text', // Important! } ], [ 'google-analytics_analytics.js', { - alias: 'google-analytics.com/analytics.js', + alias: [ + 'google-analytics.com/analytics.js', + 'googletagmanager_gtm.js', + 'googletagmanager.com/gtm.js' + ], data: 'text', } ], [ 'google-analytics_cx_api.js', { @@ -96,10 +100,6 @@ const redirectableResources = new Map([ alias: 'googlesyndication.com/adsbygoogle.js', data: 'text', } ], - [ 'googletagmanager_gtm.js', { - alias: 'googletagmanager.com/gtm.js', - data: 'text', - } ], [ 'googletagservices_gpt.js', { alias: 'googletagservices.com/gpt.js', data: 'text', diff --git a/src/web_accessible_resources/google-analytics_analytics.js b/src/web_accessible_resources/google-analytics_analytics.js index a3203e2be..7ae84ff0f 100644 --- a/src/web_accessible_resources/google-analytics_analytics.js +++ b/src/web_accessible_resources/google-analytics_analytics.js @@ -74,8 +74,17 @@ w[gaName] = ga; // https://github.com/gorhill/uBlock/issues/3075 const dl = w.dataLayer; - if ( dl instanceof Object && dl.hide instanceof Object && typeof dl.hide.end === 'function' ) { - dl.hide.end(); + if ( dl instanceof Object ) { + if ( dl.hide instanceof Object && typeof dl.hide.end === 'function' ) { + dl.hide.end(); + } + if ( typeof dl.push === 'function' ) { + dl.push = function(o) { + if ( o instanceof Object && typeof o.eventCallback === 'function' ) { + setTimeout(o.eventCallback, 1); + } + }; + } } // empty ga queue if ( gaQueue instanceof Function && Array.isArray(gaQueue.q) ) {