Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browsi RTD : add split key #11445

Merged
merged 88 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
6121b4e
real time data module,
omerDotan Aug 25, 2019
1a80b14
change timeout&primary ad server only to auctionDelay
omerDotan Sep 9, 2019
3b85815
support multiple providers
omerDotan Sep 18, 2019
0cb7b69
change promise to callbacks
omerDotan Oct 16, 2019
0908134
bug fixes
omerDotan Nov 3, 2019
cf4c5a9
use Prebid ajax
omerDotan Nov 6, 2019
7beeee3
tests fix
omerDotan Nov 6, 2019
60aaeaa
browsi real time data provider improvements
omerDotan Dec 8, 2019
0e06e6f
real time data module,
omerDotan Aug 25, 2019
e9312c7
change timeout&primary ad server only to auctionDelay
omerDotan Sep 9, 2019
c0901fe
support multiple providers
omerDotan Sep 18, 2019
398f922
change promise to callbacks
omerDotan Oct 16, 2019
b3d0bea
bug fixes
omerDotan Nov 3, 2019
a4f2de6
use Prebid ajax
omerDotan Nov 6, 2019
65ed991
tests fix
omerDotan Nov 6, 2019
15337d2
browsi real time data provider improvements
omerDotan Dec 8, 2019
76b3208
Merge remote-tracking branch 'origin/master'
omerDotan Dec 12, 2019
6a8c111
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 16, 2020
b9b05f0
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 20, 2020
89013d7
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 21, 2020
342484c
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 22, 2020
faa02bf
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 28, 2020
88430b1
Merge remote-tracking branch 'upstream/master'
omerDotan Feb 11, 2020
b73b6d7
Merge remote-tracking branch 'upstream/master'
omerDotan Feb 23, 2020
00c027c
Merge remote-tracking branch 'upstream/master'
omerDotan Apr 2, 2020
51555b6
Merge remote-tracking branch 'upstream/master'
omerDotan Apr 7, 2020
c959997
Merge remote-tracking branch 'upstream/master'
omerDotan Apr 21, 2020
a277d65
Merge remote-tracking branch 'upstream/master'
omerDotan May 4, 2020
ebf1fa8
Merge remote-tracking branch 'upstream/master'
omerDotan May 25, 2020
6ec752e
Merge remote-tracking branch 'upstream/master'
omerDotan May 28, 2020
6af3494
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 13, 2020
f0d9bb7
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 20, 2020
608eabf
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 21, 2020
6bdd935
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 26, 2020
ca43a02
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 10, 2020
8346da4
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 23, 2020
1f5a82e
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 27, 2020
1c0d024
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 14, 2020
6c7cac7
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 21, 2020
1543516
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 23, 2020
efe5ddf
Merge remote-tracking branch 'upstream/master'
omerDotan Oct 4, 2020
b404b69
Merge remote-tracking branch 'upstream/master'
omerDotan Nov 2, 2020
107f00c
Merge remote-tracking branch 'upstream/master'
omerDotan Nov 25, 2020
cea0004
Merge remote-tracking branch 'upstream/master'
omerDotan May 18, 2021
2dcd7af
Merge remote-tracking branch 'upstream/master'
omerDotan Jun 6, 2021
86d4cf7
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 5, 2021
191056f
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 29, 2021
97c94b2
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 8, 2021
ede3d7f
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 10, 2021
e435be5
Merge remote-tracking branch 'upstream/master'
omerDotan Oct 11, 2021
6a2293e
Merge remote-tracking branch 'upstream/master'
omerDotan Oct 17, 2021
f918fb8
Merge remote-tracking branch 'upstream/master'
omerDotan Nov 21, 2021
60d8c5c
Merge remote-tracking branch 'upstream/master'
omerDotan Dec 22, 2021
a1f37fd
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 12, 2022
6dd4ea3
Merge remote-tracking branch 'upstream/master'
omerDotan Feb 1, 2022
66e782e
Merge remote-tracking branch 'upstream/master'
omerDotan Feb 3, 2022
2f16e37
Merge remote-tracking branch 'upstream/master'
omerDotan Feb 9, 2022
1c577d8
Merge remote-tracking branch 'upstream/master'
omerDotan Feb 16, 2022
a52ac36
Merge remote-tracking branch 'upstream/master'
omerDotan Feb 20, 2022
3505c14
Merge remote-tracking branch 'upstream/master'
omerDotan Mar 13, 2022
1a6da04
Merge remote-tracking branch 'upstream/master'
omerDotan Apr 11, 2022
d5f83b5
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 12, 2022
02c5eae
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 2, 2022
3fca8ef
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 14, 2022
5ccd7db
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 31, 2022
9684d53
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 15, 2022
0f7ff71
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 20, 2022
42eae36
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 29, 2022
074a392
Merge remote-tracking branch 'upstream/master'
omerDotan Oct 23, 2022
ee3a43c
Merge remote-tracking branch 'upstream/master'
omerDotan Oct 26, 2022
f58a3f6
Merge remote-tracking branch 'upstream/master'
omerDotan Nov 6, 2022
75df2d7
Merge remote-tracking branch 'upstream/master'
omerDotan Dec 20, 2022
26fbcdc
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 3, 2023
74f2018
Merge remote-tracking branch 'upstream/master'
omerDotan Jan 31, 2023
ded0889
Merge remote-tracking branch 'upstream/master'
omerDotan Apr 25, 2023
d7cb814
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 17, 2023
7d07cfe
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 27, 2023
12831ea
Merge remote-tracking branch 'upstream/master'
omerDotan Dec 5, 2023
a83edc1
Merge remote-tracking branch 'upstream/master'
omerDotan Dec 10, 2023
46f0128
Merge remote-tracking branch 'upstream/master'
omerDotan Dec 26, 2023
81e079d
Merge remote-tracking branch 'upstream/master'
omerDotan May 2, 2024
0ed1201
Merge remote-tracking branch 'upstream/master'
omerDotan May 2, 2024
7df0fb5
browsi-rtd-kv
omerDotan May 6, 2024
936fbac
browsi-rtd-kv (lint)
omerDotan May 6, 2024
05a0422
Merge remote-tracking branch 'upstream/master'
omerDotan May 8, 2024
1032946
Merge branch 'master' into browsiRTD-kv
omerDotan May 8, 2024
1de2ad8
unit tests
omerDotan May 8, 2024
418e44f
lint fix
omerDotan May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions modules/browsiRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @property {string} pubKey
* @property {string} url
* @property {?string} keyName
* @property {?string} splitKey
*/

import {deepClone, deepSetValue, isFn, isGptPubadsDefined, isNumber, logError, logInfo, generateUUID} from '../src/utils.js';
Expand All @@ -33,6 +34,7 @@ import {MODULE_TYPE_RTD} from '../src/activities/modules.js';
const MODULE_NAME = 'browsi';

const storage = getStorageManager({moduleType: MODULE_TYPE_RTD, moduleName: MODULE_NAME});
const RANDOM = Math.floor(Math.random() * 10) + 1;

/** @type {ModuleParams} */
let _moduleParams = {};
Expand All @@ -58,12 +60,22 @@ export function addBrowsiTag(data) {
script.setAttribute('id', 'browsi-tag');
script.setAttribute('src', data.u);
script.prebidData = deepClone(typeof data === 'string' ? Object(data) : data)
script.brwRandom = RANDOM;
if (_moduleParams.keyName) {
script.prebidData.kn = _moduleParams.keyName;
}
return script;
}

export function setKeyValue(key) {
if (!key || typeof key !== 'string') return false;
window.googletag = window.googletag || {cmd: []};
window.googletag.cmd = window.googletag.cmd || [];
window.googletag.cmd.push(() => {
window.googletag.pubads().setTargeting(key, RANDOM.toString());
});
}

export function sendPageviewEvent(eventType) {
if (eventType === 'PAGEVIEW') {
window.addEventListener('browsi_pageview', () => {
Expand Down Expand Up @@ -380,6 +392,7 @@ function init(moduleConfig) {
_moduleParams = moduleConfig.params;
if (_moduleParams && _moduleParams.siteKey && _moduleParams.pubKey && _moduleParams.url) {
collectData();
setKeyValue(_moduleParams.splitKey);
} else {
logError('missing params for Browsi provider');
}
Expand Down
33 changes: 29 additions & 4 deletions test/spec/modules/browsiRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as browsiRTD from '../../../modules/browsiRtdProvider.js';
import {makeSlot} from '../integration/faker/googletag.js';
import * as utils from '../../../src/utils'
import * as events from '../../../src/events';
import * as sinon from 'sinon';
import {sendPageviewEvent} from '../../../modules/browsiRtdProvider.js';
import * as mockGpt from 'test/spec/integration/faker/googletag.js';

describe('browsi Real time data sub module', function () {
const conf = {
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('browsi Real time data sub module', function () {
});

it('should match placement with ad unit', function () {
const slot = makeSlot({code: '/123/abc', divId: 'browsiAd_1'});
const slot = mockGpt.makeSlot({code: '/123/abc', divId: 'browsiAd_1'});

const test1 = browsiRTD.isIdMatchingAdUnit(slot, ['/123/abc']); // true
const test2 = browsiRTD.isIdMatchingAdUnit(slot, ['/123/abc', '/456/def']); // true
Expand All @@ -69,7 +69,7 @@ describe('browsi Real time data sub module', function () {
});

it('should return correct macro values', function () {
const slot = makeSlot({code: '/123/abc', divId: 'browsiAd_1'});
const slot = mockGpt.makeSlot({code: '/123/abc', divId: 'browsiAd_1'});

slot.setTargeting('test', ['test', 'value']);
// slot getTargeting doesn't act like GPT so we can't expect real value
Expand All @@ -90,7 +90,7 @@ describe('browsi Real time data sub module', function () {
});

it('should return prediction from server', function () {
makeSlot({code: 'hasPrediction', divId: 'hasPrediction'});
mockGpt.makeSlot({code: 'hasPrediction', divId: 'hasPrediction'});
const data = {
p: {'hasPrediction': {ps: {0: 0.234}}},
kn: 'bv',
Expand Down Expand Up @@ -266,4 +266,29 @@ describe('browsi Real time data sub module', function () {
expect(eventsEmitSpy.callCount).to.equal(0);
})
})

describe('set targeting - invalid params', function () {
it('should return false if key is undefined', function () {
expect(browsiRTD.setKeyValue()).to.equal(false);
})
it('should return false if key is not string', function () {
expect(browsiRTD.setKeyValue(1)).to.equal(false);
})
})
describe('set targeting - valid params', function () {
let slot;
const splitKey = 'splitTest';
before(() => {
mockGpt.reset();
window.googletag.pubads().clearTargeting();
slot = mockGpt.makeSlot({code: '/123/split', divId: 'split'});
browsiRTD.setKeyValue(splitKey);
window.googletag.cmd.forEach(cmd => cmd());
})
it('should place numeric key value on all slots', function () {
const targetingValue = window.googletag.pubads().getTargeting(splitKey);
expect(targetingValue).to.be.an('array').that.is.not.empty;
expect(targetingValue[0]).to.be.a('string');
})
})
});