Skip to content

Commit

Permalink
Merge pull request #155 from prebid/148_inherit_bid_settings
Browse files Browse the repository at this point in the history
Fix for #148
  • Loading branch information
mkendall07 committed Jan 6, 2016
2 parents b052781 + b9abd05 commit ba37238
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
29 changes: 15 additions & 14 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,11 @@ exports.createEmptyBidResponseObj = function() {
};

exports.getKeyValueTargetingPairs = function(bidderCode, custBidObj) {
//retrive key value settings
var keyValues = {};
var bidder_settings = pbjs.bidderSettings || {};
//first try to add based on bidderCode configuration
if (bidderCode && custBidObj && bidder_settings && bidder_settings[bidderCode]) {
//
setKeys(keyValues, bidder_settings[bidderCode], custBidObj);
custBidObj.alwaysUseBid = bidder_settings[bidderCode].alwaysUseBid;
}
//next try with defaultBidderSettings
else if (defaultBidderSettingsMap[bidderCode]) {
setKeys(keyValues, defaultBidderSettingsMap[bidderCode], custBidObj);
custBidObj.alwaysUseBid = defaultBidderSettingsMap[bidderCode].alwaysUseBid;
}
//now try with "generic" settings
else if (custBidObj && bidder_settings) {

//1) set the keys from prebid defaults
if (custBidObj && bidder_settings) {
if (!bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD]) {
bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD] = {
adserverTargeting: [{
Expand Down Expand Up @@ -259,6 +248,18 @@ exports.getKeyValueTargetingPairs = function(bidderCode, custBidObj) {
setKeys(keyValues, bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD], custBidObj);
}

//2) set keys from inherited setting
if (defaultBidderSettingsMap[bidderCode]) {
setKeys(keyValues, defaultBidderSettingsMap[bidderCode], custBidObj);
custBidObj.alwaysUseBid = defaultBidderSettingsMap[bidderCode].alwaysUseBid;
}
//3) set keys from specific bidder setting
if (bidderCode && custBidObj && bidder_settings && bidder_settings[bidderCode]) {
//
setKeys(keyValues, bidder_settings[bidderCode], custBidObj);
custBidObj.alwaysUseBid = bidder_settings[bidderCode].alwaysUseBid;
}

return keyValues;
};

Expand Down
45 changes: 42 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ var bidmanager = require('../src/bidmanager');

describe('bidmanager.js', function(){



describe('getKeyValueTargetingPairs', function(){
var bid = {};
var bidPriceCpm = 5.578;
Expand All @@ -42,7 +40,6 @@ var bidmanager = require('../src/bidmanager');
var adId = '1adId';

before(function() {
console.log(pbjs);
bid.cpm = bidPriceCpm;
bid.pbLg = bidPbLg;
bid.pbMg = bidPbMg;
Expand Down Expand Up @@ -177,5 +174,47 @@ var bidmanager = require('../src/bidmanager');

});

it('Custom configuration for one bidder and inherit standard', function() {
pbjs.bidderSettings =
{
appnexus: {
bidCpmAdjustment : function(bidCpm){
return bidCpm * 0.7;
},
},
standard: {
adserverTargeting: [{
key: "hb_bidder",
val: function(bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: "hb_adid",
val: function(bidResponse) {
return bidResponse.adId;
}
}, {
key: "hb_pb",
val: function(bidResponse) {
//change default here
return 10.00;
}
}, {
key: "hb_size",
val: function(bidResponse) {
return bidResponse.size;

}
}]

}
};

var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": 10.0 ,"hb_size": size};
var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid);
assert.deepEqual(response, expected);

});

});
});

0 comments on commit ba37238

Please sign in to comment.