Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Moschovas committed Sep 26, 2024
1 parent 541278e commit b783214
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 16 additions & 1 deletion test/spec/unit/core/targeting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b783214

Please sign in to comment.