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

Extending the Real Time Data Module #5519

Merged
merged 34 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 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
74a4102
RTD module extend #4610
omerDotan Jul 20, 2020
735e8e9
add hook for submodule init
omerDotan Aug 2, 2020
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
32 changes: 20 additions & 12 deletions modules/browsiRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ let _moduleParams = {};
let _data = null;
/** @type {null | function} */
let _dataReadyCallback = null;
/** @type {string} */
const DEF_KEYNAME = 'browsiViewability';

/**
* add browsi script to page
Expand Down Expand Up @@ -117,16 +119,14 @@ function waitForData(callback) {
function sendDataToModule(adUnits, onDone) {
try {
waitForData(_predictionsData => {
const _predictions = _predictionsData.p;
if (!_predictions || !Object.keys(_predictions).length) {
return onDone({});
}
const _predictions = _predictionsData.p || {};
let dataToReturn = adUnits.reduce((rp, cau) => {
const adUnitCode = cau && cau.code;
if (!adUnitCode) { return rp }
const adSlot = getSlotByCode(adUnitCode);
const identifier = adSlot ? getMacroId(_predictionsData.pmd, adSlot) : adUnitCode;
const predictionData = _predictions[identifier];
rp[adUnitCode] = getKVObject(-1, _predictionsData.kn);
if (!predictionData) { return rp }

if (predictionData.p) {
Expand Down Expand Up @@ -160,7 +160,7 @@ function getAllSlots() {
function getKVObject(p, keyName) {
const prValue = p < 0 ? 'NA' : (Math.floor(p * 10) / 10).toFixed(2);
let prObject = {};
prObject[((_moduleParams['keyName'] || keyName).toString())] = prValue.toString();
prObject[((_moduleParams['keyName'] || keyName || DEF_KEYNAME).toString())] = prValue.toString();
return prObject;
}
/**
Expand Down Expand Up @@ -231,7 +231,7 @@ function evaluate(macro, divId, adUnit, replacer) {
* @param {string} url server url with query params
*/
function getPredictionsFromServer(url) {
let ajax = ajaxBuilder(_moduleParams.auctionDelay || _moduleParams.timeout || DEF_TIMEOUT);
let ajax = ajaxBuilder(_moduleParams.auctionDelay || _moduleParams.timeout);

ajax(url,
{
Expand Down Expand Up @@ -286,27 +286,35 @@ export const browsiSubmodule = {
* @param {adUnit[]} adUnits
* @param {function} onDone
*/
getData: sendDataToModule
getData: sendDataToModule,
init: init
};

export function init(config) {
function init(config, gdpr, usp) {
return true;
}

export function beforeInit(config) {
const confListener = config.getConfig(MODULE_NAME, ({realTimeData}) => {
try {
_moduleParams = realTimeData.dataProviders && realTimeData.dataProviders.filter(
pr => pr.name && pr.name.toLowerCase() === 'browsi')[0].params;
confListener();
_moduleParams.auctionDelay = realTimeData.auctionDelay;
_moduleParams.timeout = realTimeData.timeout;
_moduleParams.timeout = realTimeData.timeout || DEF_TIMEOUT;
} catch (e) {
_moduleParams = {};
}
if (_moduleParams.siteKey && _moduleParams.pubKey && _moduleParams.url) {
confListener();
collectData();
} else {
utils.logError('missing params for Browsi provider');
}
});
}

submodule('realTimeData', browsiSubmodule);
init(config);
function registerSubModule() {
submodule('realTimeData', browsiSubmodule);
}
registerSubModule();
beforeInit(config);
Loading