Skip to content

Commit

Permalink
Bugfix: internal bids requested overwritten (#1173)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Nate Cozi authored and matthewlane committed May 3, 2017
1 parent d6fd130 commit 41526ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
22 changes: 10 additions & 12 deletions src/adapters/prebidServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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});
}
});
Expand Down
9 changes: 1 addition & 8 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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
*/
Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

0 comments on commit 41526ba

Please sign in to comment.