Skip to content

Commit

Permalink
Manually merge bidManager code to auction module (#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiminpanchal27 authored and Matt Kendall committed Dec 5, 2017
1 parent cb4018a commit d5f0a21
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 53 deletions.
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 @@ -251,8 +251,8 @@ export const addBidResponse = createHook('asyncSeries', function(adUnitCode, bid
doCallbacksIfNeeded();
});
} else {
doCallbacksIfNeeded();
addBidToAuction(bidResponse);
doCallbacksIfNeeded();
}
}
}, 'addBidResponse');
Expand Down Expand Up @@ -319,48 +319,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 @@ -384,11 +385,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 @@ -433,12 +430,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

0 comments on commit d5f0a21

Please sign in to comment.