Skip to content

Commit

Permalink
add prebid-ads redirect #190 AG-12558
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/scriptlets from fix/AG-12558 to release/v1.6

Squashed commit of the following:

commit b89b88b
Merge: 68813a6 7f8bebf
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Fri Feb 18 16:36:56 2022 +0300

    Merge branch 'release/v1.6' into fix/AG-12558

commit 68813a6
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Fri Feb 18 13:43:28 2022 +0300

    update compatibility-table

commit 13cc688
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Fri Feb 18 13:15:15 2022 +0300

    description fix

commit 9e7e637
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Fri Feb 18 12:59:57 2022 +0300

    rename redirect

commit 6181870
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Thu Feb 17 17:13:39 2022 +0300

    add constant-detection-stubs redirect
  • Loading branch information
stanislav-atr committed Feb 18, 2022
1 parent 7f8bebf commit c55dfb2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/compatibility-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@
{
"adg": "noopvast-3.0"
},
{
"adg": "prebid-ads",
"ubo": "prebid-ads.js"
},
{
"adg": "prevent-bab",
"ubo": "nobab.js"
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/compatibility-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ const redirects = [
{
adg: 'tagcommander-tc',
},
{
adg: 'prebid-ads',
ubo: 'prebid-ads.js',
},
];

export default redirects;
30 changes: 30 additions & 0 deletions src/redirects/prebid-ads.js
Original file line number Diff line number Diff line change
@@ -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];
1 change: 1 addition & 0 deletions src/redirects/redirects-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 1 addition & 0 deletions tests/redirects/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ import './prevent-bab2.test';
import './tagcommander-tc.test';
import './prebid.test';
import './didomi-loader.test';
import './prebid-ads.test';
28 changes: 28 additions & 0 deletions tests/redirects/prebid-ads.test.js
Original file line number Diff line number Diff line change
@@ -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');
});

0 comments on commit c55dfb2

Please sign in to comment.