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

Fix for #1628 (allowing standard bidCpmAdjustment) #1645

Merged
merged 2 commits into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
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
93 changes: 50 additions & 43 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,16 @@ events.on(CONSTANTS.EVENTS.BID_ADJUSTMENT, function (bid) {
function adjustBids(bid) {
var code = bid.bidderCode;
var bidPriceAdjusted = bid.cpm;
if (code && $$PREBID_GLOBAL$$.bidderSettings && $$PREBID_GLOBAL$$.bidderSettings[code]) {
if (typeof $$PREBID_GLOBAL$$.bidderSettings[code].bidCpmAdjustment === 'function') {
let bidCpmAdjustment;
if ($$PREBID_GLOBAL$$.bidderSettings) {
if (code && $$PREBID_GLOBAL$$.bidderSettings[code] && typeof $$PREBID_GLOBAL$$.bidderSettings[code].bidCpmAdjustment === 'function') {
bidCpmAdjustment = $$PREBID_GLOBAL$$.bidderSettings[code].bidCpmAdjustment;
} else if ($$PREBID_GLOBAL$$.bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD] && typeof $$PREBID_GLOBAL$$.bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD].bidCpmAdjustment === 'function') {
bidCpmAdjustment = $$PREBID_GLOBAL$$.bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD].bidCpmAdjustment;
}
if (bidCpmAdjustment) {
try {
bidPriceAdjusted = $$PREBID_GLOBAL$$.bidderSettings[code].bidCpmAdjustment.call(null, bid.cpm, Object.assign({}, bid));
bidPriceAdjusted = bidCpmAdjustment(bid.cpm, Object.assign({}, bid));
} catch (e) {
utils.logError('Error during bid adjustment', 'bidmanager.js', e);
}
Expand All @@ -454,48 +460,49 @@ function getStandardBidderSettings() {
let granularity = config.getConfig('priceGranularity');
let bidder_settings = $$PREBID_GLOBAL$$.bidderSettings;
if (!bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD]) {
bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_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) {
if (granularity === CONSTANTS.GRANULARITY_OPTIONS.AUTO) {
return bidResponse.pbAg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.DENSE) {
return bidResponse.pbDg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.LOW) {
return bidResponse.pbLg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.MEDIUM) {
return bidResponse.pbMg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.HIGH) {
return bidResponse.pbHg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.CUSTOM) {
return bidResponse.pbCg;
}
}
}, {
key: 'hb_size',
val: function (bidResponse) {
return bidResponse.size;
}
}, {
key: 'hb_deal',
val: function (bidResponse) {
return bidResponse.dealId;
bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD] = {};
}
if (!bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) {
bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = [
{
key: 'hb_bidder',
val: function (bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: 'hb_adid',
val: function (bidResponse) {
return bidResponse.adId;
}
}, {
key: 'hb_pb',
val: function (bidResponse) {
if (granularity === CONSTANTS.GRANULARITY_OPTIONS.AUTO) {
return bidResponse.pbAg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.DENSE) {
return bidResponse.pbDg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.LOW) {
return bidResponse.pbLg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.MEDIUM) {
return bidResponse.pbMg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.HIGH) {
return bidResponse.pbHg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.CUSTOM) {
return bidResponse.pbCg;
}
}
]
};
}, {
key: 'hb_size',
val: function (bidResponse) {
return bidResponse.size;
}
}, {
key: 'hb_deal',
val: function (bidResponse) {
return bidResponse.dealId;
}
}
];
}
return bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD];
}
Expand Down
26 changes: 25 additions & 1 deletion test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('bidmanager.js', function () {
assert.deepEqual(response, expected);
});

it('Custom bidCpmAdjustment for one bidder and inherit standard', function () {
it('Custom bidCpmAdjustment for one bidder and inherit standard but doesn\'t use standard bidCpmAdjustment', function () {
$$PREBID_GLOBAL$$.bidderSettings =
{
appnexus: {
Expand All @@ -207,6 +207,9 @@ describe('bidmanager.js', function () {
},
},
standard: {
bidCpmAdjustment: function (bidCpm) {
return 200;
},
adserverTargeting: [
{
key: 'hb_bidder',
Expand Down Expand Up @@ -235,6 +238,27 @@ describe('bidmanager.js', function () {
assert.deepEqual(response, expected);
});

it('Standard bidCpmAdjustment changes the bid of any bidder', function () {
const bid = Object.assign({},
bidfactory.createBid(2),
fixtures.getBidResponses()[5]
);

assert.equal(bid.cpm, 0.5);

$$PREBID_GLOBAL$$.bidderSettings =
{
standard: {
bidCpmAdjustment: function (bidCpm) {
return bidCpm * 0.5;
}
}
};

bidmanager.adjustBids(bid)
assert.equal(bid.cpm, 0.25);
});

it('Custom bidCpmAdjustment AND custom configuration for one bidder and inherit standard settings', function () {
$$PREBID_GLOBAL$$.bidderSettings =
{
Expand Down