From a405382ec23bddba64f494ec1617036779ac34e0 Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Wed, 7 Feb 2018 20:33:54 -0800 Subject: [PATCH] Update openrtb endpoint response interpreter --- modules/prebidServerBidAdapter.js | 46 ++++++++++++++----------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index d249ada60b3..066653b9490 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -377,34 +377,30 @@ const openRtb = { const bids = []; if (response.seatbid) { - response.seatbid.forEach(bidObj => { - let cpm = bidObj.bid[0].price; - let status; - if (cpm !== 0) { - status = STATUS.GOOD; - } else { - status = STATUS.NO_BID; - } - - let bidObject = bidfactory.createBid(status); + // a seatbid object contains a `bid` array and a `seat` string + response.seatbid.forEach(seatbid => { + (seatbid.bid || []).forEach(bid => { + const cpm = bid.price; + const status = cpm !== 0 ? STATUS.GOOD : STATUS.NO_BID; + let bidObject = bidfactory.createBid(status); - bidObject.source = TYPE; - bidObject.creative_id = bidObj.crid; - bidObject.bidderCode = bidObj.seat; - bidObject.cpm = cpm; - bidObject.ad = bidObj.bid[0].adm; - - bidObject.width = bidObj.bid[0].w; - bidObject.height = bidObj.bid[0].h; - bidObject.requestId = bidObj.bid[0].id; - bidObject.creativeId = bidObj.bid[0].crid; + bidObject.source = TYPE; + bidObject.creative_id = bid.crid; + bidObject.bidderCode = seatbid.seat; + bidObject.cpm = cpm; + bidObject.ad = bid.adm; + bidObject.width = bid.w; + bidObject.height = bid.h; + bidObject.requestId = bid.id; + bidObject.creativeId = bid.crid; - // TODO: Remove when prebid-server returns ttl, currency and netRevenue - bidObject.ttl = (bidObj.ttl) ? bidObj.ttl : DEFAULT_S2S_TTL; - bidObject.currency = (bidObj.currency) ? bidObj.currency : DEFAULT_S2S_CURRENCY; - bidObject.netRevenue = (bidObj.netRevenue) ? bidObj.netRevenue : DEFAULT_S2S_NETREVENUE; + // TODO: Remove when prebid-server returns ttl, currency and netRevenue + bidObject.ttl = (bid.ttl) ? bid.ttl : DEFAULT_S2S_TTL; + bidObject.currency = (bid.currency) ? bid.currency : DEFAULT_S2S_CURRENCY; + bidObject.netRevenue = (bid.netRevenue) ? bid.netRevenue : DEFAULT_S2S_NETREVENUE; - bids.push({ adUnit: bidObj.bid[0].impid, bid: bidObject }); + bids.push({ adUnit: bid.impid, bid: bidObject }); + }); }); }