From c55dfb296cb89d9c42de8a24e882652f6be30ac9 Mon Sep 17 00:00:00 2001 From: Stanislav Atroschenko Date: Fri, 18 Feb 2022 16:41:27 +0300 Subject: [PATCH] add prebid-ads redirect #190 AG-12558 Merge in ADGUARD-FILTERS/scriptlets from fix/AG-12558 to release/v1.6 Squashed commit of the following: commit b89b88b67613c0294d2a9b4e4800d7e090467c6a Merge: 68813a6 7f8bebf Author: Stanislav A Date: Fri Feb 18 16:36:56 2022 +0300 Merge branch 'release/v1.6' into fix/AG-12558 commit 68813a6ead6ffbd90073a188a30eda000220ce1f Author: Stanislav A Date: Fri Feb 18 13:43:28 2022 +0300 update compatibility-table commit 13cc68823528033e767d1c5d64a3f9f85bbbfa0e Author: Stanislav A Date: Fri Feb 18 13:15:15 2022 +0300 description fix commit 9e7e637f2d3badb3649983dbd167cf75d197bd7f Author: Stanislav A Date: Fri Feb 18 12:59:57 2022 +0300 rename redirect commit 6181870132dd87b6487a944f136cf0cbf083a74b Author: Stanislav A Date: Thu Feb 17 17:13:39 2022 +0300 add constant-detection-stubs redirect --- scripts/compatibility-table.json | 4 ++++ src/helpers/compatibility-redirects.js | 4 ++++ src/redirects/prebid-ads.js | 30 ++++++++++++++++++++++++++ src/redirects/redirects-list.js | 1 + tests/redirects/index.test.js | 1 + tests/redirects/prebid-ads.test.js | 28 ++++++++++++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 src/redirects/prebid-ads.js create mode 100644 tests/redirects/prebid-ads.test.js diff --git a/scripts/compatibility-table.json b/scripts/compatibility-table.json index 4e16799d5..dbe2447cc 100644 --- a/scripts/compatibility-table.json +++ b/scripts/compatibility-table.json @@ -342,6 +342,10 @@ { "adg": "noopvast-3.0" }, + { + "adg": "prebid-ads", + "ubo": "prebid-ads.js" + }, { "adg": "prevent-bab", "ubo": "nobab.js" diff --git a/src/helpers/compatibility-redirects.js b/src/helpers/compatibility-redirects.js index 1a7540e49..8d115346a 100644 --- a/src/helpers/compatibility-redirects.js +++ b/src/helpers/compatibility-redirects.js @@ -167,6 +167,10 @@ const redirects = [ { adg: 'tagcommander-tc', }, + { + adg: 'prebid-ads', + ubo: 'prebid-ads.js', + }, ]; export default redirects; diff --git a/src/redirects/prebid-ads.js b/src/redirects/prebid-ads.js new file mode 100644 index 000000000..353301b3a --- /dev/null +++ b/src/redirects/prebid-ads.js @@ -0,0 +1,30 @@ +/* eslint-disable func-names */ +import { hit } from '../helpers'; + +/** + * @redirect prebid-ads + * + * @description + * Sets predefined constants on a page: + * - `canRunAds`: `true` + * - `isAdBlockActive`: `false` + * + * **Example** + * ``` + * ||playerdrive.me/assets/js/prebid-ads.js$script,redirect=prebid-ads + * ``` + */ +export function prebidAds(source) { + window.canRunAds = true; + window.isAdBlockActive = false; + + hit(source); +} + +prebidAds.names = [ + 'prebid-ads', + 'ubo-prebid-ads.js', + 'prebid-ads.js', +]; + +prebidAds.injections = [hit]; diff --git a/src/redirects/redirects-list.js b/src/redirects/redirects-list.js index 543e58acb..f9e45ec41 100644 --- a/src/redirects/redirects-list.js +++ b/src/redirects/redirects-list.js @@ -21,3 +21,4 @@ export * from './google-ima3'; export * from './tagcommander-tc.js'; export * from './didomi-loader.js'; export * from './prebid.js'; +export * from './prebid-ads.js'; diff --git a/tests/redirects/index.test.js b/tests/redirects/index.test.js index d461a879a..bdd371641 100644 --- a/tests/redirects/index.test.js +++ b/tests/redirects/index.test.js @@ -16,3 +16,4 @@ import './prevent-bab2.test'; import './tagcommander-tc.test'; import './prebid.test'; import './didomi-loader.test'; +import './prebid-ads.test'; diff --git a/tests/redirects/prebid-ads.test.js b/tests/redirects/prebid-ads.test.js new file mode 100644 index 000000000..c60a9e03e --- /dev/null +++ b/tests/redirects/prebid-ads.test.js @@ -0,0 +1,28 @@ +/* eslint-disable no-underscore-dangle */ +import { runRedirect, clearGlobalProps } from '../helpers'; + +const { test, module } = QUnit; +const name = 'prebid-ads'; + +const changingProps = ['hit', '__debug']; + +const beforeEach = () => { + window.__debug = () => { + window.hit = 'FIRED'; + }; +}; + +const afterEach = () => { + clearGlobalProps(...changingProps); +}; + +module(name, { beforeEach, afterEach }); + +test('constants are set', (assert) => { + runRedirect(name); + + assert.true(window.canRunAds, 'window.canRunAds created'); + assert.false(window.isAdBlockActive, 'Piwik.isAdBlockActive created'); + + assert.strictEqual(window.hit, 'FIRED', 'hit function was executed'); +});