Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance/refactor hb deal #935

Merged
merged 5 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -23,8 +23,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 @@ -95,14 +94,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 @@ -157,7 +150,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 @@ -171,16 +167,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