Skip to content

Commit

Permalink
Maintenance/refactor hb deal (prebid#935)
Browse files Browse the repository at this point in the history
* refactored the way hb_deal is handled in adserverTargeting

* Add Sharethrough adapter (prebid#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
  • Loading branch information
Nate Cozi authored and matthewlane committed Jan 19, 2017
1 parent caf92b2 commit 8303597
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/adapters/sharethrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
14 changes: 8 additions & 6 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -404,6 +401,11 @@ function getStandardBidderSettings() {
val: function (bidResponse) {
return bidResponse.size;
}
}, {
key: 'hb_deal',
val: function (bidResponse) {
return bidResponse.dealId;
}
}
]
};
Expand Down
3 changes: 2 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"hb_bidder",
"hb_adid",
"hb_pb",
"hb_size"
"hb_size",
"hb_deal"
]
}
26 changes: 6 additions & 20 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/spec/adapters/sharethrough_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('sharethrough adapter', () => {
],
"stxUserId": ""
};

pbjs.strcallback(bidderReponse1);
pbjs.strcallback(bidderReponse2);

Expand Down
5 changes: 4 additions & 1 deletion test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

});
});

Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 8303597

Please sign in to comment.