Skip to content

Commit

Permalink
Pass Deal IDs on bids to ad server as targeting data (prebid#390)
Browse files Browse the repository at this point in the history
If a bid response contains a dealId, its ad server targeting will receive a key with the form `hb_deal_<bidderCode>`. Bids with the highest cpm still always win whether they contain a deal or not. If a winning bid does have a dealId, its ad server targeting will also have a key of `hb_deal` with the value of the deal id. Deals are always sent to the server, regardless of whether `enableSendAllBids` is on or off.

* Construct required key/value pairs for bids with deals
* Always attach bids with deals to targeting
* Test addBidResponse places dealIds in adserver targeting
  • Loading branch information
matthewlane authored and protonate committed Jun 15, 2016
1 parent f9edc5c commit a9252fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ exports.addBidResponse = function (adUnitCode, bid) {
var keyValues = {};
if (bid.bidderCode && bid.cpm !== 0) {
keyValues = getKeyValueTargetingPairs(bid.bidderCode, bid);

if (bid.dealId) {
keyValues[`hb_deal_${bid.bidderCode}`] = bid.dealId;
}

bid.adserverTargeting = keyValues;
}

Expand Down
26 changes: 25 additions & 1 deletion src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ function getWinningBidTargeting() {
timeToRespond: 0
}));

// winning bids with deals need an hb_deal targeting key
winners
.filter(bid => bid.dealId)
.map(bid => bid.adserverTargeting.hb_deal = bid.dealId);

winners = winners.map(winner => {
return {
[winner.adUnitCode]: Object.keys(winner.adserverTargeting, key => key)
Expand All @@ -171,6 +176,22 @@ function getWinningBidTargeting() {
return winners;
}

function getDealTargeting() {
const dealTargeting = pbjs._bidsReceived.filter(bid => bid.dealId).map(bid => {
const dealKey = `hb_deal_${bid.bidderCode}`;
return {
[bid.adUnitCode]: CONSTANTS.TARGETING_KEYS.map(key => {
return {
[`${key}_${bid.bidderCode}`.substring(0, 20)]: [bid.adserverTargeting[key]]
};
})
.concat({ [dealKey]: [bid.adserverTargeting[dealKey]] })
};
});

return dealTargeting;
}

function getBidLandscapeTargeting() {
const standardKeys = CONSTANTS.TARGETING_KEYS;

Expand All @@ -188,7 +209,10 @@ function getBidLandscapeTargeting() {
}

function getAllTargeting() {
return getWinningBidTargeting().concat(pb_sendAllBids ? getBidLandscapeTargeting() : []);
let targeting = getWinningBidTargeting();
// deals are always attached to targeting
targeting = getDealTargeting().concat(targeting);
return targeting.concat(pb_sendAllBids ? getBidLandscapeTargeting() : []);
}

//////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,17 @@ describe('bidmanager.js', function () {
registeredBid = pbjs._bidsReceived.pop();
assert.equal(registeredBid.pbDg, expectedIncrement, '20+ caps at 20.00');
});

it('should place dealIds in adserver targeting', () => {
const bid = Object.assign({},
bidfactory.createBid(2),
fixtures.getBidResponses()[0]
);

bid.dealId = "test deal";
bidmanager.addBidResponse(bid.adUnitCode, bid);
const addedBid = pbjs._bidsReceived.pop();
assert.equal(addedBid.adserverTargeting[`hb_deal_${bid.bidderCode}`], bid.dealId, 'dealId placed in adserverTargeting');
});
});
});

0 comments on commit a9252fa

Please sign in to comment.