Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows multiple bids to be registered per a slot. fixes #496 #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 40 additions & 29 deletions src/adapters/rubicon.js
Original file line number Diff line number Diff line change
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);

// 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 !== undefined && ads.deal !== "") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you just copied this code, but I think it would be better to change it to if (ads.deal) { rather than checking for undefined and an empty string.

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 @@ -265,7 +276,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