From d7972a444c3f28967198245699d74bb7aaeb6480 Mon Sep 17 00:00:00 2001 From: Nate Cozi Date: Wed, 18 Jan 2017 16:45:00 -0800 Subject: [PATCH] Maintenance/refactor hb deal (#935) * refactored the way hb_deal is handled in adserverTargeting * Add Sharethrough adapter (#865) * Rz/submit to prebid (#4) Added Sharethrough Adapter * fix warnings * added beacons * made compatible with chrome 37. other minor changes * win beacon fired in analytics adapter * specs for new analytics adapter * add try catch blocks. misc refactor * removed test page * remove debugger * refactor analytics adapter * removed test endpoint * analytics url parameter is empty * removed bidwon listener on adapter * removed analytics from package.json * refactor hb_deal targeting key as a standard key * rollback errant style fixes * more fixes --- src/adapters/sharethrough.js | 2 +- src/bidmanager.js | 14 +++++++------ src/constants.json | 3 ++- src/targeting.js | 26 ++++++------------------- test/spec/adapters/sharethrough_spec.js | 2 +- test/spec/bidmanager_spec.js | 5 ++++- 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/adapters/sharethrough.js b/src/adapters/sharethrough.js index 2732d7144791..a9d26ecf23e6 100644 --- a/src/adapters/sharethrough.js +++ b/src/adapters/sharethrough.js @@ -16,7 +16,7 @@ var SharethroughAdapter = function SharethroughAdapter() { const bids = params.bids; addEventListener("message", _receiveMessage, false); - + // cycle through bids for (let i = 0; i < bids.length; i += 1) { const bidRequest = bids[i]; diff --git a/src/bidmanager.js b/src/bidmanager.js index ffd4b24632bf..380403b0d3dc 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -130,12 +130,8 @@ exports.addBidResponse = function (adUnitCode, bid) { //if there is any key value pairs to map do here var keyValues = {}; - if (bid.bidderCode && (bid.cpm > 0 || bid.dealId)) { + if (bid.bidderCode && bid.cpm > 0) { keyValues = getKeyValueTargetingPairs(bid.bidderCode, bid); - - if (bid.dealId) { - keyValues[`hb_deal_${bid.bidderCode}`] = bid.dealId; - } } bid.adserverTargeting = keyValues; @@ -204,7 +200,8 @@ function setKeys(keyValues, bidderSettings, custBidObj) { } if ( - typeof bidderSettings.suppressEmptyKeys !== "undefined" && bidderSettings.suppressEmptyKeys === true && + (typeof bidderSettings.suppressEmptyKeys !== "undefined" && bidderSettings.suppressEmptyKeys === true || + key === "hb_deal") && // hb_deal is suppressed automatically if not set ( utils.isEmptyStr(value) || value === null || @@ -404,6 +401,11 @@ function getStandardBidderSettings() { val: function (bidResponse) { return bidResponse.size; } + }, { + key: 'hb_deal', + val: function (bidResponse) { + return bidResponse.dealId; + } } ] }; diff --git a/src/constants.json b/src/constants.json index 921670d476e3..4d029c87458d 100644 --- a/src/constants.json +++ b/src/constants.json @@ -54,6 +54,7 @@ "hb_bidder", "hb_adid", "hb_pb", - "hb_size" + "hb_size", + "hb_deal" ] } diff --git a/src/targeting.js b/src/targeting.js index 7299da9bbca6..2abb8a0972dc 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -29,8 +29,7 @@ targeting.getAllTargeting = function(adUnitCode) { // `alwaysUseBid=true`. If sending all bids is enabled, add targeting for losing bids. var targeting = getWinningBidTargeting(adUnitCodes) .concat(getAlwaysUseBidTargeting(adUnitCodes)) - .concat($$PREBID_GLOBAL$$._sendAllBids ? getBidLandscapeTargeting(adUnitCodes) : []) - .concat(getDealTargeting(adUnitCodes)); + .concat($$PREBID_GLOBAL$$._sendAllBids ? getBidLandscapeTargeting(adUnitCodes) : []); //store a reference of the targeting keys targeting.map(adUnitCode => { @@ -101,14 +100,8 @@ targeting.setTargetingForAst = function() { function getWinningBidTargeting() { let winners = targeting.getWinningBids(); - - // winning bids with deals need an hb_deal targeting key - // adding hb_deal to bid.adserverTargeting if it exists in winners array - winners - .filter(bid => bid.dealId) - .map(bid => bid.adserverTargeting.hb_deal = bid.dealId); - let standardKeys = getStandardKeys(); + winners = winners.map(winner => { return { [winner.adUnitCode]: Object.keys(winner.adserverTargeting) @@ -163,7 +156,10 @@ function getBidLandscapeTargeting(adUnitCodes) { .map(bid => { if (bid.adserverTargeting) { return { - [bid.adUnitCode]: getTargetingMap(bid, standardKeys) + [bid.adUnitCode]: getTargetingMap(bid, standardKeys.filter( + key => typeof bid.adserverTargeting[key] !== 'undefined') // mainly for possibly + // unset hb_deal + ) }; } }).filter(bid => bid); // removes empty elements in array @@ -177,16 +173,6 @@ function getTargetingMap(bid, keys) { }); } -function getDealTargeting() { - return $$PREBID_GLOBAL$$._bidsReceived.filter(bid => bid.dealId).map(bid => { - const dealKey = `hb_deal_${bid.bidderCode}`; - return { - [bid.adUnitCode]: getTargetingMap(bid, CONSTANTS.TARGETING_KEYS) - .concat({ [dealKey.substring(0, 20)]: [bid.adserverTargeting[dealKey]] }) - }; - }); -} - targeting.isApntagDefined = function() { if (window.apntag && utils.isFn(window.apntag.setKeywords)) { return true; diff --git a/test/spec/adapters/sharethrough_spec.js b/test/spec/adapters/sharethrough_spec.js index 83e207e0199f..0678690370ec 100644 --- a/test/spec/adapters/sharethrough_spec.js +++ b/test/spec/adapters/sharethrough_spec.js @@ -116,7 +116,7 @@ describe('sharethrough adapter', () => { ], "stxUserId": "" }; - + pbjs.strcallback(bidderReponse1); pbjs.strcallback(bidderReponse2); diff --git a/test/spec/bidmanager_spec.js b/test/spec/bidmanager_spec.js index cb2d60c7ca88..602f0beacfcb 100644 --- a/test/spec/bidmanager_spec.js +++ b/test/spec/bidmanager_spec.js @@ -422,6 +422,9 @@ describe('bidmanager.js', function () { bidmanager.adjustBids(bid) assert.equal(bid.cpm, 0); + // reset bidderSettings so we don't mess up further tests + $$PREBID_GLOBAL$$.bidderSettings = {}; + }); }); @@ -474,7 +477,7 @@ describe('bidmanager.js', function () { bid.dealId = "test deal"; bidmanager.addBidResponse(bid.adUnitCode, bid); const addedBid = $$PREBID_GLOBAL$$._bidsReceived.pop(); - assert.equal(addedBid.adserverTargeting[`hb_deal_${bid.bidderCode}`], bid.dealId, 'dealId placed in adserverTargeting'); + assert.equal(addedBid.adserverTargeting[`hb_deal`], bid.dealId, 'dealId placed in adserverTargeting'); }); it('should not alter bid adID', () => {