From d26f0b46ddfd4421c422b0b6427fdab999b590db Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 3 Apr 2018 09:24:08 -0400 Subject: [PATCH 1/2] initial commit to fix issue 2327 --- src/targeting.js | 6 ++++- test/spec/unit/core/targeting_spec.js | 37 ++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/targeting.js b/src/targeting.js index 54324265a21..ee44baa98e5 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -328,7 +328,11 @@ export function newTargeting(auctionManager) { }); // populate targeting keys for the remaining bids return bids.map(bid => { - if (bid.adserverTargeting) { + if ( + bid.adserverTargeting && adUnitCodes && + ((utils.isArray(adUnitCodes) && adUnitCodes.includes(bid.adUnitCode)) || + (typeof adUnitCodes === 'string' && bid.adUnitCode === adUnitCodes)) + ) { return { [bid.adUnitCode]: getTargetingMap(bid, standardKeys.filter( key => typeof bid.adserverTargeting[key] !== 'undefined') diff --git a/test/spec/unit/core/targeting_spec.js b/test/spec/unit/core/targeting_spec.js index 0954dda6325..c7eb3623e08 100644 --- a/test/spec/unit/core/targeting_spec.js +++ b/test/spec/unit/core/targeting_spec.js @@ -66,6 +66,36 @@ const bid2 = { 'ttl': 300 }; +const bid3 = { + 'bidderCode': 'rubicon', + 'width': '300', + 'height': '600', + 'statusMessage': 'Bid available', + 'adId': '48747745', + 'cpm': 0.75, + 'ad': 'markup', + 'ad_id': '3163950', + 'sizeId': '15', + 'requestTimestamp': 1454535718610, + 'responseTimestamp': 1454535724863, + 'timeToRespond': 123, + 'pbLg': '0.75', + 'pbMg': '0.75', + 'pbHg': '0.75', + 'adUnitCode': '/123456/header-bid-tag-1', + 'bidder': 'rubicon', + 'size': '300x600', + 'adserverTargeting': { + 'hb_bidder': 'rubicon', + 'hb_adid': '48747745', + 'hb_pb': '0.75', + 'foobar': '300x600' + }, + 'netRevenue': true, + 'currency': 'USD', + 'ttl': 300 +}; + describe('targeting tests', () => { describe('getAllTargeting', () => { let amBidsReceivedStub; @@ -75,7 +105,7 @@ describe('targeting tests', () => { beforeEach(() => { $$PREBID_GLOBAL$$._sendAllBids = false; amBidsReceivedStub = sinon.stub(auctionManager, 'getBidsReceived').callsFake(function() { - return [bid1, bid2]; + return [bid1, bid2, bid3]; }); amGetAdUnitsStub = sinon.stub(auctionManager, 'getAdUnitCodes').callsFake(function() { return ['/123456/header-bid-tag-0']; @@ -92,9 +122,14 @@ describe('targeting tests', () => { it('selects the top bid when _sendAllBids true', () => { 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) // we shouldn't get more than 1 key for hb_pb_${bidder} expect(sendAllBidCpm.length).to.equal(1); + // expect the winning CPM to be equal to the sendAllBidCPM expect(targeting['/123456/header-bid-tag-0']['hb_pb_rubicon']).to.deep.equal(targeting['/123456/header-bid-tag-0']['hb_pb']); }); From a69b291203659412dc44ef91319778bd1c0b9720 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 3 Apr 2018 10:27:26 -0400 Subject: [PATCH 2/2] switched to different include function --- src/targeting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targeting.js b/src/targeting.js index ee44baa98e5..852a45b6bac 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -330,7 +330,7 @@ export function newTargeting(auctionManager) { return bids.map(bid => { if ( bid.adserverTargeting && adUnitCodes && - ((utils.isArray(adUnitCodes) && adUnitCodes.includes(bid.adUnitCode)) || + ((utils.isArray(adUnitCodes) && includes(adUnitCodes, bid.adUnitCode)) || (typeof adUnitCodes === 'string' && bid.adUnitCode === adUnitCodes)) ) { return {