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

Real Time Data Module - Phase3 #5783

Merged
merged 56 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 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
608eabf
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 21, 2020
6bdd935
Merge remote-tracking branch 'upstream/master'
omerDotan Jul 26, 2020
735e8e9
add hook for submodule init
omerDotan Aug 2, 2020
ca43a02
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 10, 2020
959673d
RTD bug fix
omerDotan Aug 23, 2020
8346da4
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 23, 2020
bd7f7d5
Merge branch 'master' into RTD-extend
omerDotan Aug 23, 2020
1fb1f31
remove auction delay and related hooks
omerDotan Aug 26, 2020
1f5a82e
Merge remote-tracking branch 'upstream/master'
omerDotan Aug 27, 2020
1c0d024
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 14, 2020
f757932
Merge branch 'master' into RTD-phase3
omerDotan Sep 14, 2020
6c7cac7
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 21, 2020
17d7150
Merge branch 'master' into RTD-phase3
omerDotan Sep 21, 2020
1543516
Merge remote-tracking branch 'upstream/master'
omerDotan Sep 23, 2020
3345930
Merge branch 'master' into RTD-phase3
omerDotan Sep 23, 2020
6e7805b
RTD phase 3
omerDotan Sep 23, 2020
5c9d00b
design changes
omerDotan Oct 4, 2020
efe5ddf
Merge remote-tracking branch 'upstream/master'
omerDotan Oct 4, 2020
0bfb153
Merge branch 'master' into RTD-phase3
omerDotan Oct 4, 2020
06b069e
fix loop continuation
bretg Oct 9, 2020
db41bf8
proper fix this time
bretg Oct 9, 2020
6c4ec0d
linter
bretg Oct 9, 2020
578049e
reduce loops
omerDotan Oct 13, 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
122 changes: 36 additions & 86 deletions modules/browsiRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,21 @@
* @property {string} pubKey
* @property {string} url
* @property {?string} keyName
* @property {?number} auctionDelay
* @property {?number} timeout
*/

import {config} from '../src/config.js';
import * as utils from '../src/utils.js';
import {submodule} from '../src/hook.js';
import {ajaxBuilder} from '../src/ajax.js';
import {loadExternalScript} from '../src/adloader.js';
import { getStorageManager } from '../src/storageManager.js';
import {getStorageManager} from '../src/storageManager.js';
import find from 'core-js-pure/features/array/find.js';

const storage = getStorageManager();

/** @type {string} */
const MODULE_NAME = 'realTimeData';
/** @type {number} */
const DEF_TIMEOUT = 1000;
/** @type {ModuleParams} */
let _moduleParams = {};
/** @type {null|Object} */
let _data = null;
/** @type {null | function} */
let _dataReadyCallback = null;
let _predictionsData = null;
/** @type {string} */
const DEF_KEYNAME = 'browsiViewability';

Expand All @@ -63,7 +54,7 @@ export function addBrowsiTag(data) {
* collect required data from page
* send data to browsi server to get predictions
*/
function collectData() {
export function collectData() {
const win = window.top;
const doc = win.document;
let browsiData = null;
Expand All @@ -88,59 +79,33 @@ function collectData() {
}

export function setData(data) {
_data = data;

if (typeof _dataReadyCallback === 'function') {
_dataReadyCallback(_data);
_dataReadyCallback = null;
}
}

/**
* wait for data from server
* call callback when data is ready
* @param {function} callback
*/
function waitForData(callback) {
if (_data) {
_dataReadyCallback = null;
callback(_data);
} else {
_dataReadyCallback = callback;
}
_predictionsData = data;
}

/**
* filter server data according to adUnits received
* call callback (onDone) when data is ready
* @param {adUnit[]} adUnits
* @param {function} onDone callback function
*/
function sendDataToModule(adUnits, onDone) {
function sendDataToModule(adUnitsCodes) {
try {
waitForData(_predictionsData => {
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) {
if (!isIdMatchingAdUnit(adSlot, predictionData.w)) {
return rp;
}
rp[adUnitCode] = getKVObject(predictionData.p, _predictionsData.kn);
const _predictions = (_predictionsData && _predictionsData.p) || {};
return adUnitsCodes.reduce((rp, adUnitCode) => {
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) {
if (!isIdMatchingAdUnit(adSlot, predictionData.w)) {
return rp;
}
return rp;
}, {});
return onDone(dataToReturn);
});
rp[adUnitCode] = getKVObject(predictionData.p, _predictionsData.kn);
}
return rp;
}, {});
} catch (e) {
onDone({});
return {};
}
}

Expand Down Expand Up @@ -231,7 +196,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);
let ajax = ajaxBuilder();

ajax(url,
{
Expand Down Expand Up @@ -283,38 +248,23 @@ export const browsiSubmodule = {
/**
* get data and send back to realTimeData module
* @function
* @param {adUnit[]} adUnits
* @param {function} onDone
* @param {string[]} adUnitsCodes
*/
getData: sendDataToModule,
init: init
getTargetingData: sendDataToModule,
init: init,
};

function init(config, gdpr, usp) {
function init(moduleConfig) {
_moduleParams = moduleConfig.params;
if (_moduleParams && _moduleParams.siteKey && _moduleParams.pubKey && _moduleParams.url) {
collectData();
} else {
utils.logError('missing params for Browsi provider');
}
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 || DEF_TIMEOUT;
} catch (e) {
_moduleParams = {};
}
if (_moduleParams.siteKey && _moduleParams.pubKey && _moduleParams.url) {
collectData();
} else {
utils.logError('missing params for Browsi provider');
}
});
}

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