diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index e20e6aee345..25d37f2c93e 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -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 = { @@ -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); } @@ -695,13 +700,13 @@ 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'); @@ -709,7 +714,7 @@ const OPEN_RTB_PROTOCOL = { // 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))); } @@ -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); } } diff --git a/src/adapterManager.js b/src/adapterManager.js index 2108bb7a4f6..14f158f9f3c 100644 --- a/src/adapterManager.js +++ b/src/adapterManager.js @@ -69,7 +69,9 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src}) 'fpd', 'mediaType', 'renderer', - 'storedAuctionResponse' + 'storedAuctionResponse', + 'seatBidId', + 'pbsBidId' ])); let { diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index c7d7a3ee41b..fb545793504 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -254,7 +254,6 @@ const RESPONSE_OPENRTB = { 'adm': '', 'adid': '29681110', 'adomain': ['appnexus.com'], - 'wurl': 'http://wurl.org?id=333', 'iurl': 'http://lax1-ib.adnxs.com/cr?id=2968111', 'cid': '958', 'crid': '2968111', @@ -262,7 +261,12 @@ const RESPONSE_OPENRTB = { 'w': 300, 'h': 250, 'ext': { - 'prebid': { 'type': 'banner' }, + 'prebid': { + 'type': 'banner', + 'event': { + 'win': 'http://wurl.org?id=333' + } + }, 'bidder': { 'appnexus': { 'brand_id': 1, @@ -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', @@ -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', @@ -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();