Skip to content

Commit

Permalink
Extending the Real Time Data Module (#5519)
Browse files Browse the repository at this point in the history
* real time data module,
browsi sub module for real time data,
new hook bidsBackCallback,
fix for config unsubscribe

* change timeout&primary ad server only to auctionDelay
update docs

* support multiple providers

* change promise to callbacks
configure submodule on submodules.json

* bug fixes

* use Prebid ajax

* tests fix

* browsi real time data provider improvements

* real time data module,
browsi sub module for real time data,
new hook bidsBackCallback,
fix for config unsubscribe

* change timeout&primary ad server only to auctionDelay
update docs

* support multiple providers

* change promise to callbacks
configure submodule on submodules.json

* bug fixes

* use Prebid ajax

* tests fix

* browsi real time data provider improvements

* RTD module extend #4610

* add hook for submodule init
variables naming
  • Loading branch information
omerDotan authored Aug 19, 2020
1 parent e1100af commit 23af840
Show file tree
Hide file tree
Showing 4 changed files with 425 additions and 310 deletions.
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

0 comments on commit 23af840

Please sign in to comment.