Skip to content

Commit

Permalink
allows multiple bids to be registered per a slot, related to #496 (#503)
Browse files Browse the repository at this point in the history
* allows multiple bids to be registered per a slot, related to #496

* keep track of bid request in rubicon adapter to use when calling createBid
  • Loading branch information
snapwich authored and Matt Kendall committed Aug 17, 2016
1 parent e7eb5f4 commit bcc3356
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions src/adapters/rubicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var RubiconAdapter = function RubiconAdapter() {
* @return {Bid} a bid, for prebid
*/
function _errorBid(response, ads) {
var bidResponse = bidfactory.createBid(2);
var bidResponse = bidfactory.createBid(2, response.bid);
bidResponse.bidderCode = RUBICON_BIDDER_CODE;

// use the raw ads as the 'error'
Expand Down Expand Up @@ -99,59 +99,70 @@ var RubiconAdapter = function RubiconAdapter() {
}

/**
* Create a (successful) bid for a unit,
* Create (successful) bids for a unit,
* based on the given response
* @param {String} placement placement code/unit path
* @param {Object} response the response from rubicon
* @return {Bid} a bid objectj
*/
function _makeBid(response, ads) {
function _makeBids(response, ads) {

// if there are multiple ads, sort by CPM
ads = ads.sort(_adCpmSort);

var bidResponse = bidfactory.createBid(1);
var ad = ads[0];
var size = ad.dimensions;
var bidResponses = [];

if (!size) {
// this really shouldn't happen
utils.logError('no dimensions given', RUBICON_BIDDER_CODE, ad);
return _errorBid(response, ads);
}
ads.forEach(function(ad) {

bidResponse.bidderCode = RUBICON_BIDDER_CODE;
bidResponse.cpm = ad.cpm;
var bidResponse,
size = ad.dimensions;

// the element id is what the iframe will use to render
// itself using the rubicontag.renderCreative API
bidResponse.ad = _creative(response.getElementId(), size);
bidResponse.width = size[0];
bidResponse.height = size[1];
if (!size) {
// this really shouldn't happen
utils.logError('no dimensions given', RUBICON_BIDDER_CODE, ad);
bidResponse = _errorBid(response, ads);
} else {
bidResponse = bidfactory.createBid(1, response.bid);

// DealId
if (ads.deal !== undefined && ads.deal !== "") {
bidResponse.dealId = ads.deal;
}
bidResponse.bidderCode = RUBICON_BIDDER_CODE;
bidResponse.cpm = ad.cpm;

return bidResponse;
// the element id is what the iframe will use to render
// itself using the rubicontag.renderCreative API
bidResponse.ad = _creative(response.getElementId(), size);
bidResponse.width = size[0];
bidResponse.height = size[1];

// DealId
if (ads.deal) {
bidResponse.dealId = ads.deal;
}
}

bidResponses.push(bidResponse);

});

return bidResponses;
}

/**
* Add a success/error bid based
* Add success/error bids based
* on the response from rubicon
* @param {Object} response -- AJAX response from fastlane
*/
function _addBid(response, ads) {
function _addBids(response, ads) {
// get the bid for the placement code
var bid;
var bids;
if (!ads || ads.length === 0) {
bid = _errorBid(response, ads);
bids = [ _errorBid(response, ads) ];
} else {
bid = _makeBid(response, ads);
bids = _makeBids(response, ads);
}

bidmanager.addBidResponse(response.getElementId(), bid);
bids.forEach(function(bid) {
bidmanager.addBidResponse(response.getElementId(), bid);
});
}

/**
Expand Down Expand Up @@ -211,7 +222,7 @@ var RubiconAdapter = function RubiconAdapter() {

/**
* Define the slot using the rubicontag.defineSlot API
* @param {Object} Bidrequest
* @param {Object} bid
* @returns {RubiconSlot} Instance of RubiconSlot
*/
function _defineSlot(bid) {
Expand Down Expand Up @@ -251,6 +262,8 @@ var RubiconAdapter = function RubiconAdapter() {

slot.addKW(keywords);

slot.bid = bid;

return slot;
}

Expand All @@ -265,7 +278,7 @@ var RubiconAdapter = function RubiconAdapter() {
utils.logMessage('Rubicon Project bidding complete: ' + ((new Date).getTime() - _bidStart));

utils._each(slots, function (slot) {
_addBid(slot, slot.getRawResponses());
_addBids(slot, slot.getRawResponses());
});
}

Expand Down

0 comments on commit bcc3356

Please sign in to comment.