Skip to content

Commit

Permalink
Bid adjustment #17
Browse files Browse the repository at this point in the history
  • Loading branch information
mkendall07 committed Dec 4, 2015
1 parent 8a543e6 commit 601adf4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var _callbackExecuted = false;
var defaultBidderSettingsMap = {};
var bidderStartTimes = {};

var countme = 0;

exports.getPlacementIdByCBIdentifer = function(id) {
return pbCallbackMap[id];
};
Expand Down Expand Up @@ -145,6 +147,10 @@ exports.addBidResponse = function(adUnitCode, bid) {
if (bid.getStatusCode() === 2) {
bid.cpm = 0;
}

//emit the bidResponse event
events.emit('bidResponse', adUnitCode, bid);

var priceStringsObj = utils.getPriceBucketString(bid.cpm, bid.height, bid.width);
//append price strings
bid.pbLg = priceStringsObj.low;
Expand Down Expand Up @@ -184,8 +190,7 @@ exports.addBidResponse = function(adUnitCode, bid) {
//should never reach this code
utils.logError('Internal error in bidmanager.addBidResponse. Params: ' + adUnitCode + ' & ' + bid );
}
//emit the bidResponse event
events.emit('bidResponse', adUnitCode, bid);


} else {
//create an empty bid bid response object
Expand Down Expand Up @@ -427,3 +432,22 @@ exports.addCallback = function(id, callback, cbEvent){
externalCallbackByAdUnitArr.push(callback);
}
};

//register event for bid adjustment
events.on(CONSTANTS.EVENTS.BID_RESPONSE, function(adunit, bid) {
adjustBids(bid);
});

function adjustBids(bid){
var code = bid.bidderCode;
var bidPriceAdjusted = 0;
if(code && pbjs.bidderSettings[code]){
if(typeof pbjs.bidderSettings[code].bidCpmAdjustment === objectType_function){
bidPriceAdjusted = pbjs.bidderSettings[code].bidCpmAdjustment.call(null, bid.cpm);
}
}

if(bidPriceAdjusted !== 0){
bid.cpm = bidPriceAdjusted;
}
}

0 comments on commit 601adf4

Please sign in to comment.