Skip to content

Commit

Permalink
#17 - bid adjustments per bidder
Browse files Browse the repository at this point in the history
  • Loading branch information
mkendall07 committed Dec 8, 2015
1 parent 601adf4 commit 709ac01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
]
},
appnexus: {
bidCpmAdjustment : function(bidCpm){
return bidCpm * .9;
},
alwaysUseBid : true, // <-- new field - always send these custom keys for the specified bidder
adserverTargeting: [{
key: "custom_bidder",
Expand Down
17 changes: 11 additions & 6 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ var _callbackExecuted = false;
var defaultBidderSettingsMap = {};
var bidderStartTimes = {};

var countme = 0;

exports.getPlacementIdByCBIdentifer = function(id) {
return pbCallbackMap[id];
};
Expand Down Expand Up @@ -148,8 +146,10 @@ exports.addBidResponse = function(adUnitCode, bid) {
bid.cpm = 0;
}

//emit the bidAdjustment event before bidResponse, so bid response has the adjusted bid value
events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, bid);
//emit the bidResponse event
events.emit('bidResponse', adUnitCode, bid);
events.emit(CONSTANTS.EVENTS.BID_RESPONSE, adUnitCode, bid);

var priceStringsObj = utils.getPriceBucketString(bid.cpm, bid.height, bid.width);
//append price strings
Expand Down Expand Up @@ -434,16 +434,21 @@ exports.addCallback = function(id, callback, cbEvent){
};

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

function adjustBids(bid){
var code = bid.bidderCode;
var bidPriceAdjusted = 0;
var bidPriceAdjusted = bid.cpm;
if(code && pbjs.bidderSettings[code]){
if(typeof pbjs.bidderSettings[code].bidCpmAdjustment === objectType_function){
bidPriceAdjusted = pbjs.bidderSettings[code].bidCpmAdjustment.call(null, bid.cpm);
try{
bidPriceAdjusted = pbjs.bidderSettings[code].bidCpmAdjustment.call(null, bid.cpm);
}
catch(e){
utils.logError('Error during bid adjustment', 'bidmanager.js', e);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


"EVENTS" : {
"BID_ADJUSTMENT" : "bidAdjustment",
"BID_TIMEOUT" : "bidTimeout",
"BID_REQUESTED" : "bidRequested",
"BID_RESPONSE" : "bidResponse",
Expand Down

0 comments on commit 709ac01

Please sign in to comment.