Skip to content

Commit

Permalink
Fix prebid#3059 by returning both hb_deal and hb_deal_${bidder_code} (p…
Browse files Browse the repository at this point in the history
…rebid#3062)

* Fix prebid#3059 by returning both hb_deal and hb_deal_${bidder_code}

* Add unit test per @mkendall07
  • Loading branch information
ZLester authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent f55b34e commit 0bfa5f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,16 @@ export function newTargeting(auctionManager) {
typeof winner.sendStandardTargeting === 'undefined' ||
winner.sendStandardTargeting ||
standardKeys.indexOf(key) === -1)
.map(key => ({
[(key === 'hb_deal') ? `${key}_${winner.bidderCode}`.substring(0, MAX_DFP_KEYLENGTH) : key.substring(0, MAX_DFP_KEYLENGTH)]: [winner.adserverTargeting[key]]
}))
.reduce((acc, key) => {
const targetingValue = [winner.adserverTargeting[key]];
const targeting = { [key.substring(0, MAX_DFP_KEYLENGTH)]: targetingValue };
if (key === 'hb_deal') {
const bidderCodeTargetingKey = `${key}_${winner.bidderCode}`.substring(0, MAX_DFP_KEYLENGTH);
const bidderCodeTargeting = { [bidderCodeTargetingKey]: targetingValue };
return [...acc, targeting, bidderCodeTargeting];
}
return [...acc, targeting];
}, [])
};
});

Expand Down
15 changes: 14 additions & 1 deletion test/spec/unit/core/targeting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const bid1 = {
'hb_bidder': 'rubicon',
'hb_adid': '148018fe5e',
'hb_pb': '0.53',
'hb_deal': '1234',
'foobar': '300x250'
},
'netRevenue': true,
Expand Down Expand Up @@ -120,14 +121,26 @@ describe('targeting tests', function () {
targetingModule.isBidNotExpired.restore();
});

describe('when hb_deal is present in bid.adserverTargeting', function () {
it('returns targeting with both hb_deal and hb_deal_{bidder_code}', function () {
const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']);

// We should add both keys rather than one or the other
expect(targeting['/123456/header-bid-tag-0']).to.contain.keys('hb_deal', `hb_deal_${bid1.bidderCode}`);

// We should assign both keys the same value
expect(targeting['/123456/header-bid-tag-0']['hb_deal']).to.deep.equal(targeting['/123456/header-bid-tag-0'][`hb_deal_${bid1.bidderCode}`]);
});
});

it('selects the top bid when _sendAllBids true', function () {
config.setConfig({ enableSendAllBids: true });
let targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']);

// we should only get the targeting data for the one requested adunit
expect(Object.keys(targeting).length).to.equal(1);

let sendAllBidCpm = Object.keys(targeting['/123456/header-bid-tag-0']).filter(key => key.indexOf('hb_pb_') != -1)
let sendAllBidCpm = Object.keys(targeting['/123456/header-bid-tag-0']).filter(key => key.indexOf('hb_pb_') != -1);
// we shouldn't get more than 1 key for hb_pb_${bidder}
expect(sendAllBidCpm.length).to.equal(1);

Expand Down

0 comments on commit 0bfa5f9

Please sign in to comment.