Skip to content

Commit

Permalink
Add Mozilla's Nielsen shim script
Browse files Browse the repository at this point in the history
Redirecting the Nielsen script to to Mozilla's shim script[1] instead
of blocking it fixes some websites. Let's do that.

1 - https://searchfox.org/mozilla-central/source/browser/extensions/webcompat/shims/nielsen.js
  • Loading branch information
kzar committed Nov 28, 2023
1 parent 940eb38 commit 79a072c
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"imasdk.googleapis.com": [
{ "regexRule": "imasdk\\.googleapis\\.com\\/js\\/sdkloader\\/ima3\\.js", "surrogate": "google-ima.js" }
],
"imrworldwide.com": [
{ "regexRule": "imrworldwide\\.com\\/v60\\.js", "surrogate": "nielsen.js" }
],
"npttech.com": [
{ "regexRule": "npttech\\.com\\/advertising\\.js", "surrogate": "noop.js" }
],
Expand Down
120 changes: 120 additions & 0 deletions surrogates/nielsen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"use strict";

/* 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://searchfox.org/mozilla-central/source/browser/extensions/webcompat/shims/nielsen.js

/* eslint indent: ["error", 2], quotes: ["error", "double"],
comma-dangle: ["error", "only-multiline"], space-before-function-paren: ["error", "never"],
lines-between-class-members: ["off"] */

/**
* Bug 1760754 - Shim Nielsen tracker
*
* Sites expecting the Nielsen tracker to load properly can break if it
* is blocked. This shim mitigates that breakage by loading a stand-in.
*/

if (!window.nol_t) {
const cid = "";

let domain = "";
let schemeHost = "";
let scriptName = "";
try {
const url = document?.currentScript?.src;
const { pathname, protocol, host } = new URL(url);
domain = host.split(".").slice(0, -2).join(".");
schemeHost = `${protocol}//${host}/`;
scriptName = pathname.split("/").pop();
} catch (_) {}

class NolTracker {
constructor() {
this.CONST = {
max_tags: 20,
};
this.feat = {};
this.globals = {
cid,
content: "0",
defaultApidFile: "config250",
defaultErrorParams: {
nol_vcid: "c00",
nol_clientid: "",
},
domain,
fpidSfCodeList: [""],
init() {},
tagCurrRetry: -1,
tagMaxRetry: 3,
wlCurrRetry: -1,
wlMaxRetry: 3,
};
this.pmap = [];
this.pvar = {
cid,
content: "0",
cookies_enabled: "n",
server: domain,
};
this.scriptName = [scriptName];
this.version = "6.0.107";
}
addScript() {}
catchLinkOverlay() {}
clickEvent() {}
clickTrack() {}
// eslint-disable-next-line camelcase
do_sample() {}
downloadEvent() {}
eventTrack() {}
filter() {}
fireToUrl() {}
getSchemeHost() {
return schemeHost;
}
getVersion() {}
iframe() {}
// eslint-disable-next-line camelcase
in_sample() {
return true;
}
injectBsdk() {}
invite() {}
linkTrack() {}
mergeFeatures() {}
pageEvent() {}
pause() {}
populateWhitelist() {}
post() {}
postClickTrack() {}
postData() {}
postEvent() {}
postEventTrack() {}
postLinkTrack() {}
prefix() {
return "";
}
processDdrsSvc() {}
random() {}
record() {
return this;
}
regLinkOverlay() {}
regListen() {}
retrieveCiFileViaCors() {}
sectionEvent() {}
sendALink() {}
sendForm() {}
sendIt() {}
slideEvent() {}
whitelistAssigned() {}
};

window.nol_t = () => {
return new NolTracker();
};
}

0 comments on commit 79a072c

Please sign in to comment.