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

Prebid Core: Fix Media Type Price Granularity #7607

Merged
merged 4 commits into from
Oct 27, 2021
Merged
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
22 changes: 11 additions & 11 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ export const getPriceGranularity = (mediaType, bidReq) => {
* @returns {function}
*/
export const getPriceByGranularity = (granularity) => {
return (bid) => {
return (bid, bidReq) => {
granularity = granularity || getPriceGranularity(bid.mediaType, bidReq);
if (granularity === CONSTANTS.GRANULARITY_OPTIONS.AUTO) {
return bid.pbAg;
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.DENSE) {
Expand Down Expand Up @@ -646,22 +647,21 @@ export const getAdvertiserDomain = () => {
* @param {BidRequest} bidReq
* @returns {*}
*/
export function getStandardBidderSettings(mediaType, bidderCode, bidReq) {
export function getStandardBidderSettings(mediaType, bidderCode) {
// factory for key value objs
function createKeyVal(key, value) {
return {
key,
val: (typeof value === 'function')
? function (bidResponse) {
return value(bidResponse);
? function (bidResponse, bidReq) {
return value(bidResponse, bidReq);
}
: function (bidResponse) {
return getValue(bidResponse, value);
}
};
}
const TARGETING_KEYS = CONSTANTS.TARGETING_KEYS;
const granularity = getPriceGranularity(mediaType, bidReq);

let bidderSettings = $$PREBID_GLOBAL$$.bidderSettings;
if (!bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD]) {
Expand All @@ -671,7 +671,7 @@ export function getStandardBidderSettings(mediaType, bidderCode, bidReq) {
bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = [
createKeyVal(TARGETING_KEYS.BIDDER, 'bidderCode'),
createKeyVal(TARGETING_KEYS.AD_ID, 'adId'),
createKeyVal(TARGETING_KEYS.PRICE_BUCKET, getPriceByGranularity(granularity)),
createKeyVal(TARGETING_KEYS.PRICE_BUCKET, getPriceByGranularity()),
createKeyVal(TARGETING_KEYS.SIZE, 'size'),
createKeyVal(TARGETING_KEYS.DEAL, 'dealId'),
createKeyVal(TARGETING_KEYS.SOURCE, 'source'),
Expand Down Expand Up @@ -716,12 +716,12 @@ export function getKeyValueTargetingPairs(bidderCode, custBidObj, bidReq) {
// 1) set the keys from "standard" setting or from prebid defaults
if (bidderSettings) {
// initialize default if not set
const standardSettings = getStandardBidderSettings(custBidObj.mediaType, bidderCode, bidReq);
setKeys(keyValues, standardSettings, custBidObj);
const standardSettings = getStandardBidderSettings(custBidObj.mediaType, bidderCode);
setKeys(keyValues, standardSettings, custBidObj, bidReq);

// 2) set keys from specific bidder setting override if they exist
if (bidderCode && bidderSettings[bidderCode] && bidderSettings[bidderCode][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) {
setKeys(keyValues, bidderSettings[bidderCode], custBidObj);
setKeys(keyValues, bidderSettings[bidderCode], custBidObj, bidReq);
custBidObj.sendStandardTargeting = bidderSettings[bidderCode].sendStandardTargeting;
}
}
Expand All @@ -734,7 +734,7 @@ export function getKeyValueTargetingPairs(bidderCode, custBidObj, bidReq) {
return keyValues;
}

function setKeys(keyValues, bidderSettings, custBidObj) {
function setKeys(keyValues, bidderSettings, custBidObj, bidReq) {
var targeting = bidderSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING];
custBidObj.size = custBidObj.getSize();

Expand All @@ -748,7 +748,7 @@ function setKeys(keyValues, bidderSettings, custBidObj) {

if (isFn(value)) {
try {
value = value(custBidObj);
value = value(custBidObj, bidReq);
} catch (e) {
logError('bidmanager', 'ERROR', e);
}
Expand Down