Skip to content

Commit

Permalink
Small bugfix and cleanup for Prebid Server OpenRTB code (prebid#3113)
Browse files Browse the repository at this point in the history
* change bid map to bid_id map and clean up openrtb in pbs

* add src to bids in bid request when known
  • Loading branch information
snapwich authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent b248ad2 commit 91612b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
26 changes: 14 additions & 12 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,8 @@ const LEGACY_PROTOCOL = {
* Protocol spec for OpenRTB endpoint
* e.g., https://<prebid-server-url>/v1/openrtb2/auction
*/
let bidIdMap = {};
const OPEN_RTB_PROTOCOL = {

bidMap: {},

buildRequest(s2sBidRequest, bidRequests, adUnits) {
let imps = [];
let aliases = {};
Expand All @@ -368,8 +366,7 @@ const OPEN_RTB_PROTOCOL = {
adUnit.bids.forEach(bid => {
// OpenRTB response contains the adunit code and bidder name. These are
// combined to create a unique key for each bid since an id isn't returned
const key = `${adUnit.code}${bid.bidder}`;
this.bidMap[key] = bid;
bidIdMap[`${adUnit.code}${bid.bidder}`] = bid.bid_id;

// check for and store valid aliases to add to the request
if (adaptermanager.aliasRegistry[bid.bidder]) {
Expand Down Expand Up @@ -481,17 +478,22 @@ const OPEN_RTB_PROTOCOL = {
// a seatbid object contains a `bid` array and a `seat` string
response.seatbid.forEach(seatbid => {
(seatbid.bid || []).forEach(bid => {
const bidRequest = utils.getBidRequest(
this.bidMap[`${bid.impid}${seatbid.seat}`].bid_id,
bidderRequests
);
let bidRequest;
let key = `${bid.impid}${seatbid.seat}`;
if (bidIdMap[key]) {
bidRequest = utils.getBidRequest(
bidIdMap[key],
bidderRequests
);
}

const cpm = bid.price;
const status = cpm !== 0 ? STATUS.GOOD : STATUS.NO_BID;
let bidObject = bidfactory.createBid(status, bidRequest);
let bidObject = bidfactory.createBid(status, bidRequest || {
bidder: seatbid.seat,
src: TYPE
});

bidObject.source = TYPE;
bidObject.bidderCode = seatbid.seat;
bidObject.cpm = cpm;

let serverResponseTimeMs = utils.deepAccess(response, ['ext', 'responsetimemillis', seatbid.seat].join('.'));
Expand Down
7 changes: 4 additions & 3 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function getLabels(bidOrAdUnit, activeLabels) {
return {labelAll: false, labels: bidOrAdUnit.labelAny, activeLabels};
}

function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels}) {
function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src}) {
return adUnits.reduce((result, adUnit) => {
let {
active,
Expand Down Expand Up @@ -111,6 +111,7 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels}) {
bidId: bid.bid_id || utils.getUniqueIdentifierStr(),
bidderRequestId,
auctionId,
src,
bidRequestsCount: adunitCounter.getCounter(adUnit.code),
}));
}
Expand Down Expand Up @@ -207,7 +208,7 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout,
auctionId,
bidderRequestId,
tid,
bids: getBids({bidderCode, auctionId, bidderRequestId, 'adUnits': utils.deepClone(adUnitsS2SCopy), labels}),
bids: getBids({bidderCode, auctionId, bidderRequestId, 'adUnits': utils.deepClone(adUnitsS2SCopy), labels, src: CONSTANTS.S2S.SRC}),
auctionStart: auctionStart,
timeout: _s2sConfig.timeout,
src: CONSTANTS.S2S.SRC,
Expand Down Expand Up @@ -242,7 +243,7 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout,
bidderCode,
auctionId,
bidderRequestId,
bids: getBids({bidderCode, auctionId, bidderRequestId, 'adUnits': utils.deepClone(adUnitsClientCopy), labels}),
bids: getBids({bidderCode, auctionId, bidderRequestId, 'adUnits': utils.deepClone(adUnitsClientCopy), labels, src: 'client'}),
auctionStart: auctionStart,
timeout: cbTimeout,
refererInfo
Expand Down

0 comments on commit 91612b1

Please sign in to comment.