Skip to content

Commit 62df5a1

Browse files
robertrmartinezChris Pabst
authored and
Chris Pabst
committed
Prebid Core: Fix Media Type Price Granularity (prebid#7607)
* pass bidReq into targeting function and other fun stuff * pass through bidReq * allow granularity override * Superfluous argument passed
1 parent d23c0c6 commit 62df5a1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/auction.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ export const getPriceGranularity = (mediaType, bidReq) => {
613613
* @returns {function}
614614
*/
615615
export const getPriceByGranularity = (granularity) => {
616-
return (bid) => {
616+
return (bid, bidReq) => {
617+
granularity = granularity || getPriceGranularity(bid.mediaType, bidReq);
617618
if (granularity === CONSTANTS.GRANULARITY_OPTIONS.AUTO) {
618619
return bid.pbAg;
619620
} else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.DENSE) {
@@ -646,22 +647,21 @@ export const getAdvertiserDomain = () => {
646647
* @param {BidRequest} bidReq
647648
* @returns {*}
648649
*/
649-
export function getStandardBidderSettings(mediaType, bidderCode, bidReq) {
650+
export function getStandardBidderSettings(mediaType, bidderCode) {
650651
// factory for key value objs
651652
function createKeyVal(key, value) {
652653
return {
653654
key,
654655
val: (typeof value === 'function')
655-
? function (bidResponse) {
656-
return value(bidResponse);
656+
? function (bidResponse, bidReq) {
657+
return value(bidResponse, bidReq);
657658
}
658659
: function (bidResponse) {
659660
return getValue(bidResponse, value);
660661
}
661662
};
662663
}
663664
const TARGETING_KEYS = CONSTANTS.TARGETING_KEYS;
664-
const granularity = getPriceGranularity(mediaType, bidReq);
665665

666666
let bidderSettings = $$PREBID_GLOBAL$$.bidderSettings;
667667
if (!bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD]) {
@@ -671,7 +671,7 @@ export function getStandardBidderSettings(mediaType, bidderCode, bidReq) {
671671
bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = [
672672
createKeyVal(TARGETING_KEYS.BIDDER, 'bidderCode'),
673673
createKeyVal(TARGETING_KEYS.AD_ID, 'adId'),
674-
createKeyVal(TARGETING_KEYS.PRICE_BUCKET, getPriceByGranularity(granularity)),
674+
createKeyVal(TARGETING_KEYS.PRICE_BUCKET, getPriceByGranularity()),
675675
createKeyVal(TARGETING_KEYS.SIZE, 'size'),
676676
createKeyVal(TARGETING_KEYS.DEAL, 'dealId'),
677677
createKeyVal(TARGETING_KEYS.SOURCE, 'source'),
@@ -716,12 +716,12 @@ export function getKeyValueTargetingPairs(bidderCode, custBidObj, bidReq) {
716716
// 1) set the keys from "standard" setting or from prebid defaults
717717
if (bidderSettings) {
718718
// initialize default if not set
719-
const standardSettings = getStandardBidderSettings(custBidObj.mediaType, bidderCode, bidReq);
720-
setKeys(keyValues, standardSettings, custBidObj);
719+
const standardSettings = getStandardBidderSettings(custBidObj.mediaType, bidderCode);
720+
setKeys(keyValues, standardSettings, custBidObj, bidReq);
721721

722722
// 2) set keys from specific bidder setting override if they exist
723723
if (bidderCode && bidderSettings[bidderCode] && bidderSettings[bidderCode][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) {
724-
setKeys(keyValues, bidderSettings[bidderCode], custBidObj);
724+
setKeys(keyValues, bidderSettings[bidderCode], custBidObj, bidReq);
725725
custBidObj.sendStandardTargeting = bidderSettings[bidderCode].sendStandardTargeting;
726726
}
727727
}
@@ -734,7 +734,7 @@ export function getKeyValueTargetingPairs(bidderCode, custBidObj, bidReq) {
734734
return keyValues;
735735
}
736736

737-
function setKeys(keyValues, bidderSettings, custBidObj) {
737+
function setKeys(keyValues, bidderSettings, custBidObj, bidReq) {
738738
var targeting = bidderSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING];
739739
custBidObj.size = custBidObj.getSize();
740740

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

749749
if (isFn(value)) {
750750
try {
751-
value = value(custBidObj);
751+
value = value(custBidObj, bidReq);
752752
} catch (e) {
753753
logError('bidmanager', 'ERROR', e);
754754
}

0 commit comments

Comments
 (0)