diff options
Diffstat (limited to 'browser/extensions/webcompat/shims/google-analytics.js')
-rw-r--r-- | browser/extensions/webcompat/shims/google-analytics.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/browser/extensions/webcompat/shims/google-analytics.js b/browser/extensions/webcompat/shims/google-analytics.js new file mode 100644 index 0000000000..f0162b1f63 --- /dev/null +++ b/browser/extensions/webcompat/shims/google-analytics.js @@ -0,0 +1,45 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// based on https://github.com/gorhill/uBlock/blob/8a1a8b103f56e4fcef1264e02dfd718a29bda006/src/web_accessible_resources/google-analytics_analytics.js + +"use strict"; + +if (!window[window.GoogleAnalyticsObject || "ga"]) { + function ga() { + const len = arguments.length; + if (!len) { + return; + } + const args = Array.from(arguments); + let fn; + let a = args[len - 1]; + if (a instanceof Object && a.hitCallback instanceof Function) { + 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)) { + return; + } + try { + fn(); + } catch (_) {} + } + ga.create = () => {}; + ga.getByName = () => null; + ga.getAll = () => []; + ga.remove = () => {}; + ga.loaded = true; + + const gaName = window.GoogleAnalyticsObject || "ga"; + window[gaName] = ga; +} + +try { + window.dataLayer.hide.end(); +} catch (_) {} |