From c83ac4db8be661311480a5993a12164be26dbaf5 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 19 Feb 2019 11:17:02 -0500 Subject: [PATCH 1/5] move logic that assigns bid targeting params --- src/auction.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/auction.js b/src/auction.js index fc8c42023f7..4a8913eb597 100644 --- a/src/auction.js +++ b/src/auction.js @@ -386,6 +386,8 @@ export function doCallbacksIfTimedout(auctionInstance, bidResponse) { // Add a bid to the auction. export function addBidToAuction(auctionInstance, bidResponse) { + setupBidTargeting(bidResponse); + events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bidResponse); auctionInstance.addBidReceived(bidResponse); @@ -429,6 +431,12 @@ const callPrebidCache = hook('async', function(auctionInstance, bidResponse, aft doCallbacksIfTimedout(auctionInstance, bidResponse); } else { bidResponse.videoCacheKey = cacheIds[0].uuid; + let cacheTargetKeys = { + hb_uuid: cacheIds[0].uuid, + hb_cache_id: cacheIds[0].uuid + }; + bidResponse.adserverTargeting = Object.assign(bidResponse.adserverTargeting || {}, cacheTargetKeys); + if (!bidResponse.vastUrl) { bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey); } @@ -485,16 +493,17 @@ function getPreparedBidForAuction({adUnitCode, bid, bidderRequest, auctionId}) { bidObject.pbDg = priceStringsObj.dense; bidObject.pbCg = priceStringsObj.custom; - // if there is any key value pairs to map do here - var keyValues; + return bidObject; +} + +function setupBidTargeting(bidObject) { + let keyValues; if (bidObject.bidderCode && (bidObject.cpm > 0 || bidObject.dealId)) { keyValues = getKeyValueTargetingPairs(bidObject.bidderCode, bidObject); } // use any targeting provided as defaults, otherwise just set from getKeyValueTargetingPairs bidObject.adserverTargeting = Object.assign(bidObject.adserverTargeting || {}, keyValues); - - return bidObject; } export function getStandardBidderSettings(mediaType) { From 14ee9c0a81c2130b4c91a361729628907539d703 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 19 Feb 2019 11:39:51 -0500 Subject: [PATCH 2/5] switch order of targeting keys assignment in dfpAdServerVideo --- modules/dfpAdServerVideo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index 1b5f8509559..5479543a019 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -159,10 +159,10 @@ function getCustParams(bid, options) { const optCustParams = deepAccess(options, 'params.cust_params'); let customParams = Object.assign({}, allTargetingData, - adserverTargeting, { hb_uuid: bid && bid.videoCacheKey }, // hb_uuid will be deprecated and replaced by hb_cache_id { hb_cache_id: bid && bid.videoCacheKey }, + adserverTargeting, optCustParams, ); return encodeURIComponent(formatQS(customParams)); From e09f0ef69c3f2577f9e9a169cf6cf7220bacf52a Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 19 Feb 2019 13:55:28 -0500 Subject: [PATCH 3/5] remove redundant cache key assignment in dfp module and update unit tests --- modules/dfpAdServerVideo.js | 3 -- test/spec/modules/dfpAdServerVideo_spec.js | 33 ++++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index 5479543a019..17a8f0f1144 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -159,9 +159,6 @@ function getCustParams(bid, options) { const optCustParams = deepAccess(options, 'params.cust_params'); let customParams = Object.assign({}, allTargetingData, - { hb_uuid: bid && bid.videoCacheKey }, - // hb_uuid will be deprecated and replaced by hb_cache_id - { hb_cache_id: bid && bid.videoCacheKey }, adserverTargeting, optCustParams, ); diff --git a/test/spec/modules/dfpAdServerVideo_spec.js b/test/spec/modules/dfpAdServerVideo_spec.js index 8afc597d3b4..ab988ec0fe3 100644 --- a/test/spec/modules/dfpAdServerVideo_spec.js +++ b/test/spec/modules/dfpAdServerVideo_spec.js @@ -10,7 +10,10 @@ import { targeting } from 'src/targeting'; const bid = { videoCacheKey: 'abc', - adserverTargeting: { }, + adserverTargeting: { + hb_uuid: 'abc', + hb_cache_id: 'abc', + }, }; describe('The DFP video support module', function () { @@ -40,7 +43,7 @@ describe('The DFP video support module', function () { }); it('can take an adserver url as a parameter', function () { - const bidCopy = Object.assign({ }, bid); + const bidCopy = utils.deepClone(bid); bidCopy.vastUrl = 'vastUrl.example'; const url = parse(buildDfpVideoUrl({ @@ -90,10 +93,10 @@ describe('The DFP video support module', function () { }); it('should include the cache key and adserver targeting in cust_params', function () { - const bidCopy = Object.assign({ }, bid); - bidCopy.adserverTargeting = { + const bidCopy = utils.deepClone(bid); + bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, { hb_adid: 'ad_id', - }; + }); const url = parse(buildDfpVideoUrl({ adUnit: adUnit, @@ -160,10 +163,10 @@ describe('The DFP video support module', function () { } }); - const bidCopy = Object.assign({ }, bid); - bidCopy.adserverTargeting = { + const bidCopy = utils.deepClone(bid); + bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, { hb_adid: 'ad_id', - }; + }); const url = parse(buildDfpVideoUrl({ adUnit: adUnitsCopy, @@ -184,10 +187,10 @@ describe('The DFP video support module', function () { }); it('should merge the user-provided cust_params with the default ones', function () { - const bidCopy = Object.assign({ }, bid); - bidCopy.adserverTargeting = { + const bidCopy = utils.deepClone(bid); + bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, { hb_adid: 'ad_id', - }; + }); const url = parse(buildDfpVideoUrl({ adUnit: adUnit, @@ -207,10 +210,10 @@ describe('The DFP video support module', function () { }); it('should merge the user-provided cust-params with the default ones when using url object', function () { - const bidCopy = Object.assign({ }, bid); - bidCopy.adserverTargeting = { + const bidCopy = utils.deepClone(bid); + bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, { hb_adid: 'ad_id', - }; + }); const url = parse(buildDfpVideoUrl({ adUnit: adUnit, @@ -229,7 +232,7 @@ describe('The DFP video support module', function () { }); it('should not overwrite an existing description_url for object input and cache disabled', function () { - const bidCopy = Object.assign({}, bid); + const bidCopy = utils.deepClone(bid); bidCopy.vastUrl = 'vastUrl.example'; const url = parse(buildDfpVideoUrl({ From cb0d06fba5d7e6496b7904e147ff26a29a86f105 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 19 Feb 2019 14:33:58 -0500 Subject: [PATCH 4/5] refactor logic when adding cache targeting keys --- src/auction.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/auction.js b/src/auction.js index 4a8913eb597..bd6c80a576a 100644 --- a/src/auction.js +++ b/src/auction.js @@ -431,11 +431,6 @@ const callPrebidCache = hook('async', function(auctionInstance, bidResponse, aft doCallbacksIfTimedout(auctionInstance, bidResponse); } else { bidResponse.videoCacheKey = cacheIds[0].uuid; - let cacheTargetKeys = { - hb_uuid: cacheIds[0].uuid, - hb_cache_id: cacheIds[0].uuid - }; - bidResponse.adserverTargeting = Object.assign(bidResponse.adserverTargeting || {}, cacheTargetKeys); if (!bidResponse.vastUrl) { bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey); @@ -502,8 +497,14 @@ function setupBidTargeting(bidObject) { keyValues = getKeyValueTargetingPairs(bidObject.bidderCode, bidObject); } + let cacheTargetKeys = {}; + if (bidObject.videoCacheKey) { + cacheTargetKeys.hb_uuid = bidObject.videoCacheKey; + cacheTargetKeys.hb_cache_id = bidObject.videoCacheKey; + } + // use any targeting provided as defaults, otherwise just set from getKeyValueTargetingPairs - bidObject.adserverTargeting = Object.assign(bidObject.adserverTargeting || {}, keyValues); + bidObject.adserverTargeting = Object.assign(bidObject.adserverTargeting || {}, cacheTargetKeys, keyValues); } export function getStandardBidderSettings(mediaType) { From d5adf0abaee6d205a1b82df79739366408be9c2d Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Fri, 1 Mar 2019 10:09:20 -0500 Subject: [PATCH 5/5] fix issue caused by refactor from another PR --- src/auction.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/auction.js b/src/auction.js index 9b52d26676b..0ddb2450561 100644 --- a/src/auction.js +++ b/src/auction.js @@ -386,7 +386,9 @@ export function doCallbacksIfTimedout(auctionInstance, bidResponse) { // Add a bid to the auction. export function addBidToAuction(auctionInstance, bidResponse) { - setupBidTargeting(bidResponse); + let bidderRequests = auctionInstance.getBidRequests(); + let bidderRequest = find(bidderRequests, bidderRequest => bidderRequest.bidderCode === bidResponse.bidderCode); + setupBidTargeting(bidResponse, bidderRequest); events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bidResponse); auctionInstance.addBidReceived(bidResponse); @@ -491,9 +493,10 @@ function getPreparedBidForAuction({adUnitCode, bid, bidderRequest, auctionId}) { return bidObject; } -function setupBidTargeting(bidObject) { +function setupBidTargeting(bidObject, bidderRequest) { let keyValues; if (bidObject.bidderCode && (bidObject.cpm > 0 || bidObject.dealId)) { + let bidReq = find(bidderRequest.bids, bid => bid.adUnitCode === bidObject.adUnitCode); keyValues = getKeyValueTargetingPairs(bidObject.bidderCode, bidObject, bidReq); }