Skip to content

Commit

Permalink
PBJS Core: Add allowSendAllBidsTargetingKeys to targetingControls (#6822
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Ryan Schweitzer authored Jun 8, 2021
1 parent 6dd4c8f commit 038a58e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,19 @@ export function newTargeting(auctionManager) {
const standardKeys = TARGETING_KEYS.concat(NATIVE_TARGETING_KEYS);
const adUnitBidLimit = config.getConfig('sendBidsControl.bidLimit');
const bids = getHighestCpmBidsFromBidPool(bidsReceived, getHighestCpm, adUnitBidLimit);
const allowSendAllBidsTargetingKeys = config.getConfig('targetingControls.allowSendAllBidsTargetingKeys');

const allowedSendAllBidTargeting = allowSendAllBidsTargetingKeys
? allowSendAllBidsTargetingKeys.map((key) => CONSTANTS.TARGETING_KEYS[key])
: standardKeys;

// populate targeting keys for the remaining bids
return bids.map(bid => {
if (bidShouldBeAddedToTargeting(bid, adUnitCodes)) {
return {
[bid.adUnitCode]: getTargetingMap(bid, standardKeys.filter(
key => typeof bid.adserverTargeting[key] !== 'undefined')
key => typeof bid.adserverTargeting[key] !== 'undefined' &&
allowedSendAllBidTargeting.indexOf(key) !== -1)
)
};
}
Expand Down
43 changes: 43 additions & 0 deletions test/spec/unit/core/targeting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,49 @@ describe('targeting tests', function () {
});
});

describe('targetingControls.allowSendAllBidsTargetingKeys', function () {
let bid4;

beforeEach(function() {
bid4 = utils.deepClone(bid1);
bid4.adserverTargeting = {
hb_deal: '4321',
hb_pb: '0.1',
hb_adid: '567891011',
hb_bidder: 'appnexus',
};
bid4.bidder = bid4.bidderCode = 'appnexus';
bid4.cpm = 0.1; // losing bid so not included if enableSendAllBids === false
bid4.dealId = '4321';
enableSendAllBids = true;
config.setConfig({
targetingControls: {
allowTargetingKeys: ['BIDDER', 'AD_ID', 'PRICE_BUCKET'],
allowSendAllBidsTargetingKeys: ['PRICE_BUCKET', 'AD_ID']
}
});
bidsReceived.push(bid4);
});

it('targeting should include custom keys', function () {
const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']);
expect(targeting['/123456/header-bid-tag-0']).to.include.all.keys('foobar');
});

it('targeting should only include keys prefixed by allowed default send all bids targeting keys and standard keys', function () {
const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']);

expect(targeting['/123456/header-bid-tag-0']).to.include.all.keys('hb_bidder', 'hb_adid', 'hb_pb');
expect(targeting['/123456/header-bid-tag-0']).to.include.all.keys('hb_adid_rubicon', 'hb_pb_rubicon');
expect(targeting['/123456/header-bid-tag-0']).to.include.all.keys('hb_bidder', 'hb_adid', 'hb_pb', 'hb_adid_appnexus', 'hb_pb_appnexus');
});

it('targeting should not include keys prefixed by disallowed default targeting keys and disallowed send all bid targeting keys', function () {
const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']);
expect(targeting['/123456/header-bid-tag-0']).to.not.have.all.keys(['hb_deal', 'hb_bidder_rubicon', 'hb_bidder_appnexus', 'hb_deal_appnexus', 'hb_deal_rubicon']);
});
});

describe('targetingControls.alwaysIncludeDeals', function () {
let bid4;

Expand Down

0 comments on commit 038a58e

Please sign in to comment.