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

Manually merge bidManager code to auction module #1905

Merged
merged 1 commit into from
Dec 5, 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
107 changes: 55 additions & 52 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

import { uniques, flatten, timestamp, adUnitsFilter, delayExecution, getBidderRequest } from './utils';
import { getPriceBucketString } from './cpmBucketManager';
import { NATIVE_KEYS } from './native';
import { getNativeTargeting } from './native';
import { getCacheUrl, store } from './videoCache';
import { Renderer } from 'src/Renderer';
import { config } from 'src/config';
Expand Down Expand Up @@ -236,8 +236,8 @@ export const addBidResponse = createHook('asyncSeries', function(adUnitCode, bid
doCallbacksIfNeeded();
});
} else {
doCallbacksIfNeeded();
addBidToAuction(bidResponse);
doCallbacksIfNeeded();
}
}
}, 'addBidResponse');
Expand Down Expand Up @@ -304,48 +304,49 @@ export 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 All @@ -369,11 +370,7 @@ export function getKeyValueTargetingPairs(bidderCode, custBidObj) {

// set native key value targeting
if (custBidObj.native) {
Object.keys(custBidObj.native).forEach(asset => {
const key = NATIVE_KEYS[asset];
const value = custBidObj.native[asset];
if (key) { keyValues[key] = value; }
});
keyValues = Object.assign({}, keyValues, getNativeTargeting(custBidObj));
}

return keyValues;
Expand Down Expand Up @@ -418,12 +415,18 @@ function setKeys(keyValues, bidderSettings, custBidObj) {
}

export 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 code = bid.bidderCode;
let bidPriceAdjusted = bid.cpm;
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 Down
26 changes: 25 additions & 1 deletion test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('auctionmanager.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 @@ -198,6 +198,9 @@ describe('auctionmanager.js', function () {
},
},
standard: {
bidCpmAdjustment: function (bidCpm) {
return 200;
},
adserverTargeting: [
{
key: 'hb_bidder',
Expand Down Expand Up @@ -226,6 +229,27 @@ describe('auctionmanager.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;
}
}
};

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