From 41526ba4a08ff55233ac897fdc9c1f3382455834 Mon Sep 17 00:00:00 2001 From: Nate Cozi Date: Wed, 3 May 2017 14:41:26 -0700 Subject: [PATCH] Bugfix: internal bids requested overwritten (#1173) * promote getBidderRequest to utils * handle no_bid and no_cookie lookups on bidsRequested remove internal bids requested collection * no bid response creates bid with bid_ad, ad_unit --- src/adapters/prebidServer.js | 22 ++++++++++------------ src/bidmanager.js | 9 +-------- src/utils.js | 7 +++++++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/adapters/prebidServer.js b/src/adapters/prebidServer.js index 6ea2f902305..64d7e7e974c 100644 --- a/src/adapters/prebidServer.js +++ b/src/adapters/prebidServer.js @@ -15,7 +15,6 @@ const cookiePersistUrl = '//ib.adnxs.com/seg?add=1&redir='; function PrebidServer() { let baseAdapter = Adapter.createNew('prebidServer'); - let bidRequests = []; let config; baseAdapter.setConfig = function(s2sconfig) { @@ -25,12 +24,6 @@ function PrebidServer() { /* Prebid executes this function when the page asks to send out bid requests */ baseAdapter.callBids = function(bidRequest) { - bidRequest.ad_units.forEach(adUnit => { - adUnit.bids.forEach(bidder => { - bidRequests[bidder.bidder] = utils.getBidRequest(bidder.bid_id); - }); - }); - let requestJson = { account_id : config.accountId, tid : bidRequest.tid, @@ -57,13 +50,18 @@ function PrebidServer() { if(result.status === 'OK') { if(result.bidder_status) { result.bidder_status.forEach(bidder => { - if(bidder.no_bid || bidder.no_cookie) { - let bidRequest = bidRequests[bidder.bidder]; - let bidObject = bidfactory.createBid(STATUS.NO_BID, bidRequest); - bidObject.bidderCode = bidRequest.bidder; - bidmanager.addBidResponse(bidRequest.placementCode, bidObject); + if(bidder.no_bid) { + // store a "No Bid" bid response + + let bidObject = bidfactory.createBid(STATUS.NO_BID, { + bidId: bidder.bid_id + }); + bidObject.adUnitCode = bidder.ad_unit; + bidObject.bidderCode = bidder.bidder; + bidmanager.addBidResponse(bidObject.adUnitCode, bidObject); } if(bidder.no_cookie) { + // if no cookie is present then no bids were made, we don't store a bid response queueSync({bidder: bidder.bidder, url : bidder.usersync.url, type : bidder.usersync.type}); } }); diff --git a/src/bidmanager.js b/src/bidmanager.js index cb2268ac298..387524f189f 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -1,4 +1,4 @@ -import {uniques, flatten, adUnitsFilter} from './utils'; +import { uniques, flatten, adUnitsFilter, getBidderRequest } from './utils'; import {getPriceBucketString} from './cpmBucketManager'; var CONSTANTS = require('./constants.json'); @@ -82,13 +82,6 @@ exports.bidsBackAll = function () { return bidsBackAll(); }; -function getBidderRequest(bidder, adUnitCode) { - return $$PREBID_GLOBAL$$._bidsRequested.find(request => { - return request.bids - .filter(bid => bid.bidder === bidder && bid.placementCode === adUnitCode).length > 0; - }) || { start: null, requestId: null }; -} - /* * This function should be called to by the bidder adapter to register a bid response */ diff --git a/src/utils.js b/src/utils.js index c7468611b6f..5b6542d457f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -647,3 +647,10 @@ export function replaceAuctionPrice(str, cpm) { if(!str) return; return str.replace(/\$\{AUCTION_PRICE\}/g, cpm); } + +export function getBidderRequest(bidder, adUnitCode) { + return $$PREBID_GLOBAL$$._bidsRequested.find(request => { + return request.bids + .filter(bid => bid.bidder === bidder && bid.placementCode === adUnitCode).length > 0; + }) || { start: null, requestId: null }; +} \ No newline at end of file