Skip to content

Commit

Permalink
updated obj path for wurl on the bid response
Browse files Browse the repository at this point in the history
  • Loading branch information
idettman committed May 27, 2020
1 parent fcdcd0c commit 7b1223e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
44 changes: 25 additions & 19 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,32 +370,37 @@ let nativeAssetCache = {}; // store processed native params to preserve
/**
* map wurl to auction id and adId for use in the BID_WON event
*/
let wurlMap = {};
const wurlMap = {};

/**
* @param {string} auctionId the id representing the auction
* @param {string} auctionId
* @param {string} adId generated value set to bidObject.adId by bidderFactory Bid()
* @param {string} wurl events.winurl passed from prebidServer as wurl
*/
function addWurl(auctionId, adId, wurl) {
wurlMap[`${auctionId}${adId}`] = wurl;
if (![auctionId, adId].some(utils.isEmptyStr)) {
wurlMap[`${auctionId}${adId}`] = wurl;
}
}

/**
* @param {string} auctionId the id representing the auction
* @param {string} auctionId
* @param {string} adId generated value set to bidObject.adId by bidderFactory Bid()
* @param {string} wurl events.winurl passed from prebidServer as wurl
*/
function removeWurl(auctionId, adId) {
wurlMap[`${auctionId}${adId}`] = undefined;
if (![auctionId, adId].some(utils.isEmptyStr)) {
wurlMap[`${auctionId}${adId}`] = undefined;
}
}
/**
* @param {string} auctionId the id representing the auction
* @param {string} auctionId
* @param {string} adId generated value set to bidObject.adId by bidderFactory Bid()
* @return {(string|undefined)} events.winurl which was passed as wurl
*/
function getWurl(auctionId, adId) {
return wurlMap[`${auctionId}${adId}`];
if (![auctionId, adId].some(utils.isEmptyStr)) {
return wurlMap[`${auctionId}${adId}`];
}
}

const OPEN_RTB_PROTOCOL = {
Expand Down Expand Up @@ -548,7 +553,7 @@ const OPEN_RTB_PROTOCOL = {
* @type {(string|undefined)}
*/
const pbAdSlot = utils.deepAccess(adUnit, 'fpd.context.pbAdSlot');
if (typeof pbAdSlot === 'string' && !utils.isEmptyStr(pbAdSlot)) {
if (!utils.isEmptyStr(pbAdSlot)) {
utils.deepSetValue(imp, 'ext.context.data.adslot', pbAdSlot);
}

Expand Down Expand Up @@ -695,21 +700,21 @@ const OPEN_RTB_PROTOCOL = {

// Look for seatbid[].bid[].ext.prebid.bidid and place it in the bidResponse object for use in analytics adapters as 'pbsBidId'
const bidId = utils.deepAccess(bid, 'ext.prebid.bidid');
if (typeof bidId === 'string' && !utils.isEmptyStr(bidId)) {
if (!utils.isEmptyStr(bidId)) {
bidObject.pbsBidId = bidId;
}

// store wurl by auctionId and adId so it can be access from the BID_WON event handler
if (typeof bid.wurl === 'string' && !utils.isEmptyStr(bid.wurl)) {
addWurl(bidRequest.auctionId, bidObject.adId, bid.wurl);
if (!utils.isEmptyStr(utils.deepAccess(bid, 'ext.prebid.event.win'))) {
addWurl(bidRequest.auctionId, bidObject.adId, utils.deepAccess(bid, 'ext.prebid.event.win'));
}

let extPrebidTargeting = utils.deepAccess(bid, 'ext.prebid.targeting');

// If ext.prebid.targeting exists, add it as a property value named 'adserverTargeting'
if (extPrebidTargeting && typeof extPrebidTargeting === 'object') {
// If wurl exists, remove hb_winurl and hb_bidid targeting attributes
if (bid.wurl) {
if (!utils.isEmptyStr(utils.deepAccess(bid, 'ext.prebid.event.win'))) {
extPrebidTargeting = utils.getDefinedParams(extPrebidTargeting, Object.keys(extPrebidTargeting)
.filter(i => (i.indexOf('hb_winurl') === -1 && i.indexOf('hb_bidid') === -1)));
}
Expand Down Expand Up @@ -826,15 +831,16 @@ const OPEN_RTB_PROTOCOL = {

/**
* BID_WON event to request the wurl
* @param {Bid} args the winning bid object
* @param {Bid} bid the winning bid object
*/
function bidWonHandler(args) {
const wurl = getWurl(args.auctionId, args.adId);
if (typeof wurl === 'string' && !utils.isEmptyStr(wurl)) {
// can remove array item after calling the wurl
removeWurl(args.auctionId, args.adId);
function bidWonHandler(bid) {
const wurl = getWurl(bid.auctionId, bid.adId);
if (!utils.isEmptyStr(wurl)) {
utils.logMessage(`Invoking image pixel for wurl on BID_WIN: "${wurl}"`);
utils.triggerPixel(wurl);

// remove from wurl cache, since the wurl url was called
removeWurl(bid.auctionId, bid.adId);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/adapterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src})
'fpd',
'mediaType',
'renderer',
'storedAuctionResponse'
'storedAuctionResponse',
'seatBidId',
'pbsBidId'
]));

let {
Expand Down
21 changes: 15 additions & 6 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,19 @@ const RESPONSE_OPENRTB = {
'adm': '<script src="http://lax1-ib.adnxs.com/ab?e=wqT_3QKgB6CgAwAAAwDWAAUBCJ7kvtMFEPft7JnIuImSdBj87IDv8q21rXcqNgkAAAECCOA_EQEHNAAA4D8ZAAAAgOtR4D8hERIAKREJADERG6Aw8ub8BDi-B0C-B0gCUNbLkw5Y4YBIYABokUB48NIEgAEBigEDVVNEkgUG8FKYAawCoAH6AagBAbABALgBAsABA8gBAtABCdgBAOABAPABAIoCOnVmKCdhJywgNDk0NDcyLCAxNTE3MjY5NTM0KTt1ZigncicsIDI5NjgxMTEwLDIeAPCckgKBAiFqRHF3RUFpNjBJY0VFTmJMa3c0WUFDRGhnRWd3QURnQVFBUkl2Z2RROHViOEJGZ0FZUF9fX184UGFBQndBWGdCZ0FFQmlBRUJrQUVCbUFFQm9BRUJxQUVEc0FFQXVRRXBpNGlEQUFEZ1A4RUJLWXVJZ3dBQTREX0pBVkx3MU5mdl9lMF8yUUVBQUFBQUFBRHdQLUFCQVBVQgUPKEpnQ0FLQUNBTFVDBRAETDAJCPBUTUFDQWNnQ0FkQUNBZGdDQWVBQ0FPZ0NBUGdDQUlBREFaQURBSmdEQWFnRHV0Q0hCTG9ERVdSbFptRjFiSFFqVEVGWU1Ub3pPRFk1mgI5IS1ndndfUTYEAfCENFlCSUlBUW9BRG9SWkdWbVlYVnNkQ05NUVZneE9qTTROamsu2ALoB-ACx9MB6gJHaHR0cDovL3ByZWJpZC5sb2NhbGhvc3Q6OTk5OS9pbnRlZ3JhdGlvbkV4YW1wbGVzL2dwdC9hcHBuZXh1cy10ZXN0Lmh0bWzyAhAKBkFEVl9JRBIGNCXTHPICEQoGQ1BHARM4BzE5Nzc5MzPyAhAKBUNQBRPwljg1MTM1OTSAAwGIAwGQAwCYAxSgAwGqAwDAA6wCyAMA2AMA4AMA6AMA-AMDgAQAkgQJL29wZW5ydGIymAQAogQMMjE2LjU1LjQ3Ljk0qAQAsgQMCAAQABgAIAAwADgAuAQAwAQAyAQA0gQRZGVmYXVsdCNMQVgxOjM4NjnaBAIIAeAEAPAE1suTDogFAZgFAKAF______8BA7ABqgUkYzdkY2YxNGYtZjliYS00Yzc3LWEzYjQtMjdmNmRmMzkwNjdmwAUAyQVpLhTwP9IFCQkJDFAAANgFAeAFAfAFAfoFBAgAEACQBgA.&s=f4dc8b6fa65845d08f0a87c145e12cb7d6288c2a&referrer=http%3A%2F%2Fprebid.localhost%3A9999%2FintegrationExamples%2Fgpt%2Fappnexus-test.html&pp=${AUCTION_PRICE}"></script>',
'adid': '29681110',
'adomain': ['appnexus.com'],
'wurl': 'http://wurl.org?id=333',
'iurl': 'http://lax1-ib.adnxs.com/cr?id=2968111',
'cid': '958',
'crid': '2968111',
'dealid': 'test-dealid',
'w': 300,
'h': 250,
'ext': {
'prebid': { 'type': 'banner' },
'prebid': {
'type': 'banner',
'event': {
'win': 'http://wurl.org?id=333'
}
},
'bidder': {
'appnexus': {
'brand_id': 1,
Expand Down Expand Up @@ -1782,7 +1786,9 @@ describe('S2S Adapter', function () {
config.setConfig({ s2sConfig });
const cacheResponse = utils.deepClone(RESPONSE_OPENRTB_VIDEO);
cacheResponse.seatbid.forEach(item => {
item.bid[0].wurl = 'https://wurl.com?a=1&b=2';
item.bid[0].ext.prebid.event = {
win: 'https://wurl.com?a=1&b=2'
};
item.bid[0].ext.prebid.targeting = {
hb_uuid: 'a5ad3993',
hb_cache_host: 'prebid-cache.net',
Expand All @@ -1805,7 +1811,9 @@ describe('S2S Adapter', function () {
config.setConfig({ s2sConfig });
const cacheResponse = utils.deepClone(RESPONSE_OPENRTB_VIDEO);
cacheResponse.seatbid.forEach(item => {
item.bid[0].wurl = 'https://wurl.com?a=1&b=2';
item.bid[0].ext.prebid.event = {
win: 'https://wurl.com?a=1&b=2'
};
item.bid[0].ext.prebid.targeting = {
hb_uuid: 'a5ad3993',
hb_cache_host: 'prebid-cache.net',
Expand Down Expand Up @@ -1903,8 +1911,9 @@ describe('S2S Adapter', function () {
config.setConfig({ s2sConfig });

const clonedResponse = utils.deepClone(RESPONSE_OPENRTB);
const bid = clonedResponse.seatbid[0].bid[0];
bid.wurl = 'https://wurl.org';
clonedResponse.seatbid[0].bid[0].ext.prebid.event = {
win: 'https://wurl.org'
};
server.respondWith(JSON.stringify(clonedResponse));
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
server.respond();
Expand Down

0 comments on commit 7b1223e

Please sign in to comment.