summaryrefslogtreecommitdiffstats
path: root/browser/extensions/webcompat/shims/google-analytics.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /browser/extensions/webcompat/shims/google-analytics.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--browser/extensions/webcompat/shims/google-analytics.js45
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 (_) {}