Skip to content

Commit

Permalink
Feature: Multiple Prebid Servers (prebid#5992)
Browse files Browse the repository at this point in the history
* adjusted for multiple prebid servers and added and adjusted units tests

* removed exra param

* fixed unit test

* adjusted testing module to work with mutliple configs
  • Loading branch information
Ryan Schweitzer authored and icflournoy committed Feb 5, 2021
1 parent 9924c07 commit 8a7f3ea
Show file tree
Hide file tree
Showing 8 changed files with 1,705 additions and 829 deletions.
208 changes: 128 additions & 80 deletions modules/prebidServerBidAdapter/index.js

Large diffs are not rendered by default.

37 changes: 12 additions & 25 deletions modules/s2sTesting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { config } from '../src/config.js';
import { setS2STestingModule } from '../src/adapterManager.js';

let s2sTesting = {};
Expand All @@ -9,39 +8,31 @@ const CLIENT = 'client';
s2sTesting.SERVER = SERVER;
s2sTesting.CLIENT = CLIENT;

var testing = false; // whether testing is turned on
var bidSource = {}; // store bidder sources determined from s2sConfing bidderControl
s2sTesting.bidSource = {}; // store bidder sources determined from s2sConfig bidderControl
s2sTesting.globalRand = Math.random(); // if 10% of bidderA and 10% of bidderB should be server-side, make it the same 10%

// load s2sConfig
config.getConfig('s2sConfig', config => {
testing = config.s2sConfig && config.s2sConfig.testing;
s2sTesting.calculateBidSources(config.s2sConfig);
});

s2sTesting.getSourceBidderMap = function(adUnits = []) {
s2sTesting.getSourceBidderMap = function(adUnits = [], allS2SBidders = []) {
var sourceBidders = {[SERVER]: {}, [CLIENT]: {}};

// bail if testing is not turned on
if (!testing) {
return {[SERVER]: [], [CLIENT]: []};
}

adUnits.forEach((adUnit) => {
// if any adUnit bidders specify a bidSource, include them
(adUnit.bids || []).forEach((bid) => {
// When a s2sConfig does not have testing=true and did not calc bid sources
if (allS2SBidders.indexOf(bid.bidder) > -1 && !s2sTesting.bidSource[bid.bidder]) {
s2sTesting.bidSource[bid.bidder] = SERVER;
}
// calculate the source once and store on bid object
bid.calcSource = bid.calcSource || s2sTesting.getSource(bid.bidSource);
// if no bidSource at bid level, default to bidSource from bidder
bid.finalSource = bid.calcSource || bidSource[bid.bidder] || CLIENT; // default to client
bid.finalSource = bid.calcSource || s2sTesting.bidSource[bid.bidder] || CLIENT; // default to client
// add bidder to sourceBidders data structure
sourceBidders[bid.finalSource][bid.bidder] = true;
});
});

// make sure all bidders in bidSource are in sourceBidders
Object.keys(bidSource).forEach((bidder) => {
sourceBidders[bidSource[bidder]][bidder] = true;
Object.keys(s2sTesting.bidSource).forEach((bidder) => {
sourceBidders[s2sTesting.bidSource[bidder]][bidder] = true;
});

// return map of source => array of bidders
Expand All @@ -53,18 +44,14 @@ s2sTesting.getSourceBidderMap = function(adUnits = []) {

/**
* @function calculateBidSources determines the source for each s2s bidder based on bidderControl weightings. these can be overridden at the adUnit level
* @param s2sConfig server-to-server configuration
* @param s2sConfigs server-to-server configuration
*/
s2sTesting.calculateBidSources = function(s2sConfig = {}) {
// bail if testing is not turned on
if (!testing) {
return;
}
bidSource = {}; // reset bid sources
// calculate bid source (server/client) for each s2s bidder

var bidderControl = s2sConfig.bidderControl || {};
(s2sConfig.bidders || []).forEach((bidder) => {
bidSource[bidder] = s2sTesting.getSource(bidderControl[bidder] && bidderControl[bidder].bidSource) || SERVER; // default to server
s2sTesting.bidSource[bidder] = s2sTesting.getSource(bidderControl[bidder] && bidderControl[bidder].bidSource) || SERVER; // default to server
});
};

Expand Down
Loading

0 comments on commit 8a7f3ea

Please sign in to comment.