From b783214434f815aa01b6561371835a73287b6375 Mon Sep 17 00:00:00 2001 From: Michael Moschovas Date: Thu, 26 Sep 2024 14:14:33 -0400 Subject: [PATCH] fix --- src/targeting.js | 18 +++++++++++++----- test/spec/unit/core/targeting_spec.js | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/targeting.js b/src/targeting.js index fab8453110d..a7d40e6170d 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -75,10 +75,15 @@ export const getHighestCpmBidsFromBidPool = hook('sync', function(bidsReceived, // bucket by adUnitcode let buckets = groupBy(bidsReceived, 'adUnitCode'); // filter top bid for each bucket by bidder + Object.keys(buckets).forEach(bucketKey => { let bucketBids = []; let bidsByBidder = groupBy(buckets[bucketKey], 'bidderCode'); - Object.keys(bidsByBidder).forEach(key => bucketBids.push(bidsByBidder[key].reduce(winReducer))); + + Object.keys(bidsByBidder).forEach(key => { + bucketBids.push(bidsByBidder[key].reduce(winReducer)) + }); + // if adUnitBidLimit is set, pass top N number bids if (adUnitBidLimit) { bucketBids = dealPrioritization ? bucketBids.sort(sortByDealAndPriceBucketOrCpm(true)) : bucketBids.sort((a, b) => b.cpm - a.cpm); @@ -355,12 +360,14 @@ export function newTargeting(auctionManager) { function getfilteredBidsAndCustomKeys(adUnitCodes, bidsReceived) { const filteredBids = []; const customKeysByUnit = {}; + const alwaysIncludeDeals = config.getConfig('targetingControls.alwaysIncludeDeals'); bidsReceived.forEach(bid => { const adUnitIsEligible = includes(adUnitCodes, bid.adUnitCode); const cpmAllowed = bidderSettings.get(bid.bidderCode, 'allowZeroCpmBids') === true ? bid.cpm >= 0 : bid.cpm > 0; + const isPreferredDeal = alwaysIncludeDeals && bid.dealId; - if (adUnitIsEligible && cpmAllowed) { + if (adUnitIsEligible && (isPreferredDeal || cpmAllowed)) { filteredBids.push(bid); Object.keys(bid.adserverTargeting) .filter(getCustomKeys()) @@ -575,10 +582,11 @@ export function newTargeting(auctionManager) { return bidsReceived .reduce((result, bid) => { const code = bid.adUnitCode; + const cpmEligible = bidderSettings.get(code, 'allowZeroCpmBids') === true ? bid.cpm >= 0 : bid.cpm > 0; + const isPreferredDeal = config.getConfig('targetingControls.alwaysIncludeDeals') && bid.dealId; const eligible = includes(adUnitCodes, code) && - ((bidderSettings.get(code, 'allowZeroCpmBids') === true) ? bid.cpm >= 0 : bid.cpm > 0) && - !includes(usedCodes, code); - + !includes(usedCodes, code) && + (isPreferredDeal || cpmEligible) if (eligible) { result.push(bid); usedCodes.push(code); diff --git a/test/spec/unit/core/targeting_spec.js b/test/spec/unit/core/targeting_spec.js index 42a4bdae5c1..f3d0c6df442 100644 --- a/test/spec/unit/core/targeting_spec.js +++ b/test/spec/unit/core/targeting_spec.js @@ -392,13 +392,28 @@ describe('targeting tests', function () { beforeEach(function() { bid4 = utils.deepClone(bid1); bid4.adserverTargeting['hb_bidder'] = bid4.bidder = bid4.bidderCode = 'appnexus'; - bid4.cpm = 0.01; + bid4.cpm = 0; enableSendAllBids = true; bidsReceived.push(bid4); }); + after(function() { + config.setConfig({ + targetingControls: { + alwaysIncludeDeals: false + } + }); + enableSendAllBids = false; + }) + it('returns targeting with both hb_deal and hb_deal_{bidder_code}', function () { + config.setConfig({ + targetingControls: { + alwaysIncludeDeals: true + } + }); + const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']); // We should add both keys rather than one or the other