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.
This commit is contained in:
Raymond Hill 2021-05-18 11:08:20 -04:00
parent 4509df154f
commit 8cd2a1d263
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 16 additions and 7 deletions

View file

@ -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',

View file

@ -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) ) {