Skip to content

Commit

Permalink
single auctions mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
protonate committed Jun 3, 2016
1 parent a161954 commit f858ae0
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 152 deletions.
11 changes: 6 additions & 5 deletions src/adapters/adequant.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ module.exports = function() {
if (cats) { req_url.push('c='+cats.join('+')); }
if (sizes) { req_url.push('s='+sizes.join('+')); }

adloader.loadScript(req_url_base+req_url.join('&'), function() { process_bids(replies, placements); });
adloader.loadScript(req_url_base+req_url.join('&'), function() { process_bids(replies, placements, bids); });
}

function process_bids(replies, placements) {
function process_bids(replies, placements, bids) {
var placement_code, bid, adequant_creatives = window.adequant_creatives;
if (adequant_creatives && adequant_creatives.seatbid) {
for (var i=0; i<adequant_creatives.seatbid.length; i++) {
var bid_response = adequant_creatives.seatbid[i].bid[0];
placement_code = replies[parseInt(bid_response.impid,10)-1];
if (!placement_code || !placements[placement_code]) { continue; }

bid = bidfactory.createBid(1);
const bidRequestId = bids.find(bid => bid.placementCode === placement_code).bidId;
bid = bidfactory.createBid(1, bidRequestId);
bid.bidderCode = 'adequant';
bid.cpm = bid_response.price;
bid.ad = bid_response.adm;
Expand All @@ -55,8 +55,9 @@ module.exports = function() {
}
}
for (placement_code in placements) {
const bidRequestId = bids.find(bid => bid.placementCode === placement_code).bidId;
if (placements[placement_code]) {
bid = bidfactory.createBid(2);
bid = bidfactory.createBid(2, bidRequestId);
bid.bidderCode = 'adequant';
bidmanager.addBidResponse(placement_code, bid);
}
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/adform.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function AdformAdapter() {
if (adItem && adItem.response === 'banner' &&
verifySize(adItem, bid.sizes)) {

bidObject = bidfactory.createBid(1);
bidObject = bidfactory.createBid(1, bid.bidId);
bidObject.bidderCode = bidder;
bidObject.cpm = adItem.win_bid;
bidObject.cur = adItem.win_cur;
Expand All @@ -76,7 +76,7 @@ function AdformAdapter() {
bidObject.height = adItem.height;
bidmanager.addBidResponse(bid.placementCode, bidObject);
} else {
bidObject = bidfactory.createBid(2);
bidObject = bidfactory.createBid(2, bid.bidId);
bidObject.bidderCode = bidder;
bidmanager.addBidResponse(bid.placementCode, bidObject);
}
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/aol.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var AolAdapter = function AolAdapter() {
// clean up--we no longer need to store the bid
delete bidsMap[context.alias];

var bidResponse = bidfactory.createBid(1);
var bidResponse = bidfactory.createBid(1, bid.bidId);
var ad = response.getCreative();
if (typeof response.getPixels() !== 'undefined') {
ad += response.getPixels();
Expand Down Expand Up @@ -105,7 +105,7 @@ var AolAdapter = function AolAdapter() {
// clean up--we no longer need to store the bid
delete bidsMap[context.alias];

var bidResponse = bidfactory.createBid(2);
var bidResponse = bidfactory.createBid(2, bid.bidId);
bidResponse.bidderCode = ADTECH_BIDDER_NAME;
bidResponse.reason = response.getNbr();
bidResponse.raw = response.getResponse();
Expand Down
8 changes: 4 additions & 4 deletions src/adapters/appnexus.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findBidderRequestByBidId } from '../utils.js';
import { findBidRequest } from '../utils.js';

var CONSTANTS = require('../constants.json');
var utils = require('../utils.js');
Expand All @@ -13,7 +13,7 @@ AppNexusAdapter = function AppNexusAdapter() {

baseAdapter.callBids = function (params) {
params.bids.map(bid => {
const callbackId = bid.adId;
const callbackId = bid.bidId;
adloader.loadScript(buildJPTCall(bid, callbackId));
});
};
Expand Down Expand Up @@ -139,7 +139,7 @@ AppNexusAdapter = function AppNexusAdapter() {
var responseCPM;
var id = jptResponseObj.callback_uid;
var placementCode = '';
var bidObj = findBidderRequestByBidId({ adId: id });
var bidObj = findBidRequest({ bidId: id });

if (bidObj) {

Expand Down Expand Up @@ -167,7 +167,7 @@ AppNexusAdapter = function AppNexusAdapter() {
//store bid response
//bid status is good (indicating 1)
var adId = jptResponseObj.result.creative_id;
bid = bidfactory.createBid(1, adId);
bid = bidfactory.createBid(1, id);
bid.creative_id = adId;
bid.bidderCode = bidCode;
bid.cpm = responseCPM;
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/brightcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ var BrightcomAdapter = function BrightcomAdapter() {
brightcomResponseObj.seatbid[0].bid.forEach(function(curBid) {

// Get the bid request data
const auction = findAuctionByBidderCode({ bidderCode: 'brightcom' });
const auction = auction || pbjs.auctionManager.getSingleAuction();
var bidRequest = auction.getBidderRequests().find(bidSet => bidSet.bidderCode === 'brightcom').bids[0]; // this assumes a single request only

// Make sure the bid exists
Expand Down
5 changes: 3 additions & 2 deletions src/adapters/nginad.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { findBidderRequestByBidId } from '../utils';

var CONSTANTS = require('../constants.json');
var utils = require('../utils.js');
var bidfactory = require('../bidfactory.js');
Expand Down Expand Up @@ -142,8 +144,7 @@ var NginAdAdapter = function NginAdAdapter() {
var id = nginadBid.impid;

// try to fetch the bid request we sent NginAd
var bidObj = auction.getBidderRequests().find(bidSet => bidSet.bidderCode === 'nginad').bids
.find(bid => bid.bidId === id);
var bidObj = findBidderRequestByBidId({ adId: id });
if (!bidObj) {
return handleErrorResponse(nginadBid, defaultPlacementForBadBid);
}
Expand Down
104 changes: 53 additions & 51 deletions src/adapters/pubmatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var PubmaticAdapter = function PubmaticAdapter() {
bids = params.bids;
for (var i = 0; i < bids.length; i++) {
var bid = bids[i];
//bidmanager.pbCallbackMap['' + bid.params.adSlot] = bid;
_pm_pub_id = _pm_pub_id || bid.params.publisherId;
_pm_optimize_adslots.push(bid.params.adSlot);
_createHandlePubmaticCallback(bid);
}

// Load pubmatic script in an iframe, because they call document.write
Expand Down Expand Up @@ -73,57 +73,59 @@ var PubmaticAdapter = function PubmaticAdapter() {
return content;
}

pbjs.handlePubmaticCallback = function (response) {
var i;
var adUnit;
var adUnitInfo;
var bid;
var bidResponseMap = (response && response.bidDetailsMap) || {};
var bidInfoMap = (response && response.progKeyValueMap) || {};
var dimensions;

for (i = 0; i < bids.length; i++) {
var adResponse;
bid = bids[i].params;

adUnit = bidResponseMap[bid.adSlot] || {};

// adUnitInfo example: bidstatus=0;bid=0.0000;bidid=39620189@320x50;wdeal=

// if using DFP GPT, the params string comes in the format:
// "bidstatus;1;bid;5.0000;bidid;hb_test@468x60;wdeal;"
// the code below detects and handles this.
if (bidInfoMap[bid.adSlot].indexOf('=') === -1) {
bidInfoMap[bid.adSlot] = bidInfoMap[bid.adSlot].replace(/([a-z]+);(.[^;]*)/ig, '$1=$2');
function _createHandlePubmaticCallback(bidRequest) {
pbjs.handlePubmaticCallback = function (response) {
var i;
var adUnit;
var adUnitInfo;
var bid;
var bidResponseMap = (response && response.bidDetailsMap) || {};
var bidInfoMap = (response && response.progKeyValueMap) || {};
var dimensions;

for (i = 0; i < bids.length; i++) {
var adResponse;
bid = bids[i].params;

adUnit = bidResponseMap[bid.adSlot] || {};

// adUnitInfo example: bidstatus=0;bid=0.0000;bidid=39620189@320x50;wdeal=

// if using DFP GPT, the params string comes in the format:
// "bidstatus;1;bid;5.0000;bidid;hb_test@468x60;wdeal;"
// the code below detects and handles this.
if (bidInfoMap[bid.adSlot].indexOf('=') === -1) {
bidInfoMap[bid.adSlot] = bidInfoMap[bid.adSlot].replace(/([a-z]+);(.[^;]*)/ig, '$1=$2');
}

adUnitInfo = (bidInfoMap[bid.adSlot] || '').split(';').reduce(function (result, pair) {
var parts = pair.split('=');
result[parts[0]] = parts[1];
return result;
}, {});

if (adUnitInfo.bidstatus === '1') {
dimensions = adUnitInfo.bidid.split('@')[1].split('x');
adResponse = bidfactory.createBid(1, bidRequest.bidId);
adResponse.bidderCode = 'pubmatic';
adResponse.adSlot = bid.adSlot;
adResponse.cpm = Number(adUnitInfo.bid);
adResponse.ad = unescape(adUnit.creative_tag); // jshint ignore:line
adResponse.ad += utils.createTrackPixelHtml(decodeURIComponent(adUnit.tracking_url));
adResponse.width = dimensions[0];
adResponse.height = dimensions[1];
adResponse.dealId = adUnitInfo.wdeal;

bidmanager.addBidResponse(bids[i].placementCode, adResponse);
} else {
// Indicate an ad was not returned
adResponse = bidfactory.createBid(2);
adResponse.bidderCode = 'pubmatic';
bidmanager.addBidResponse(bids[i].placementCode, adResponse);
}
}

adUnitInfo = (bidInfoMap[bid.adSlot] || '').split(';').reduce(function (result, pair) {
var parts = pair.split('=');
result[parts[0]] = parts[1];
return result;
}, {});

if (adUnitInfo.bidstatus === '1') {
dimensions = adUnitInfo.bidid.split('@')[1].split('x');
adResponse = bidfactory.createBid(1);
adResponse.bidderCode = 'pubmatic';
adResponse.adSlot = bid.adSlot;
adResponse.cpm = Number(adUnitInfo.bid);
adResponse.ad = unescape(adUnit.creative_tag); // jshint ignore:line
adResponse.ad += utils.createTrackPixelHtml(decodeURIComponent(adUnit.tracking_url));
adResponse.width = dimensions[0];
adResponse.height = dimensions[1];
adResponse.dealId = adUnitInfo.wdeal;

bidmanager.addBidResponse(bids[i].placementCode, adResponse);
} else {
// Indicate an ad was not returned
adResponse = bidfactory.createBid(2);
adResponse.bidderCode = 'pubmatic';
bidmanager.addBidResponse(bids[i].placementCode, adResponse);
}
}
};
};
}

return {
callBids: _callBids
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/pulsepoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ var PulsePointAdapter = function PulsePointAdapter() {
function bidResponseAvailable(bidRequest, bidResponse) {
if (bidResponse) {
var adSize = bidRequest.params.cf.toUpperCase().split('X');
var bid = bidfactory.createBid(1);
var bid = bidfactory.createBid(1, bidRequest.bidId);
bid.bidderCode = bidRequest.bidder;
bid.cpm = bidResponse.bidCpm;
bid.ad = bidResponse.html;
bid.width = adSize[0];
bid.height = adSize[1];
bidmanager.addBidResponse(bidRequest.placementCode, bid);
} else {
var passback = bidfactory.createBid(2);
var passback = bidfactory.createBid(2, bidRequest.bidId);
passback.bidderCode = bidRequest.bidder;
bidmanager.addBidResponse(bidRequest.placementCode, passback);
}
Expand Down
5 changes: 3 additions & 2 deletions src/adapters/sovrn.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { findBidRequest } from '../utils';

var CONSTANTS = require('../constants.json');
var utils = require('../utils.js');
var bidfactory = require('../bidfactory.js');
Expand Down Expand Up @@ -104,8 +106,7 @@ var SovrnAdapter = function SovrnAdapter() {
var bid = {};

// try to fetch the bid request we sent Sovrn
var bidObj = auction.getBidderRequests().find(bidSet => bidSet.bidderCode === 'sovrn').bids
.find(bid => bid.bidId === id);
var bidObj = findBidRequest({ bidId: id });

if (bidObj) {
placementCode = bidObj.placementCode;
Expand Down
66 changes: 29 additions & 37 deletions src/adapters/springserve.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,42 @@ SpringServeAdapter = function SpringServeAdapter() {
var bids = params.bids || [];
for (var i = 0; i < bids.length; i++) {
var bid = bids[i];
//bidmanager.pbCallbackMap[bid.params.impId] = params;
pbjs.handleSpringServeCB = _createCallback(bid);
adloader.loadScript(buildSpringServeCall(bid));
}
}

pbjs.handleSpringServeCB = function (responseObj) {
if (responseObj && responseObj.seatbid && responseObj.seatbid.length > 0 &&
responseObj.seatbid[0].bid[0] !== undefined) {

var responseBid = responseObj.seatbid[0].bid[0];
var requestBids = pbjs.auctionManager.findBidderRequestByBidParamImpId(+responseBid.impid);

//var requestBids = auction.getBidderRequests()
// .find(bidSet => bidSet.bidderCode === 'springserve').bids
// .filter(bid => bid.params && bid.params.impId === +responseBid.impid);
var bid = bidfactory.createBid(1);
var placementCode;

//assign properties from the original request to the bid object
for (var i = 0; i < requestBids.length; i++) {
var bidRequest = requestBids[i];
if (bidRequest.bidder === 'springserve') {
placementCode = bidRequest.placementCode;
var size = bidRequest.sizes[0];
bid.width = size[0];
bid.height = size[1];
function _createCallback(bidRequest) {
return function _handleSpringServeCB(responseObj) {
if (responseObj && responseObj.seatbid && responseObj.seatbid.length > 0 &&
responseObj.seatbid[0].bid[0] !== undefined) {

var responseBid = responseObj.seatbid[0].bid[0];
var bid = bidfactory.createBid(1, bidRequest.bidId);
var placementCode;

//assign properties from the original request to the bid object
placementCode = bidRequest.placementCode;
var size = bidRequest.sizes[0];
bid.width = size[0];
bid.height = size[1];

bid.bidderCode = bidRequest.bidder;

if (responseBid.hasOwnProperty('price') && responseBid.hasOwnProperty('adm')) {
//assign properties from the response to the bid object
bid.cpm = responseBid.price;
bid.ad = responseBid.adm;
} else {
//make object for invalid bid response
bid = bidfactory.createBid(2, bidRequest.bidId);
bid.bidderCode = 'springserve';
}
}

bid.bidderCode = requestBids[0].bidder;

if (responseBid.hasOwnProperty('price') && responseBid.hasOwnProperty('adm')) {
//assign properties from the response to the bid object
bid.cpm = responseBid.price;
bid.ad = responseBid.adm;
} else {
//make object for invalid bid response
bid = bidfactory.createBid(2);
bid.bidderCode = 'springserve';
bidmanager.addBidResponse(placementCode, bid);
}

bidmanager.addBidResponse(placementCode, bid);
}
};
};
}

// Export the callBids function, so that prebid.js can execute this function
// when the page asks to send out bid requests.
Expand Down
Loading

0 comments on commit f858ae0

Please sign in to comment.