From 6bc6394d865dd4c35bdb69cdb502f9eadd787d8b Mon Sep 17 00:00:00 2001 From: jsnellbaker <31102355+jsnellbaker@users.noreply.github.com> Date: Mon, 4 Mar 2019 15:05:12 -0500 Subject: [PATCH] fix two issues related to hb_uuid and hb_cache_id targeting keys (#3605) * move logic that assigns bid targeting params * switch order of targeting keys assignment in dfpAdServerVideo * remove redundant cache key assignment in dfp module and update unit tests * refactor logic when adding cache targeting keys * fix issue caused by refactor from another PR --- modules/dfpAdServerVideo.js | 3 -- src/auction.js | 23 +++++++++++---- test/spec/modules/dfpAdServerVideo_spec.js | 33 ++++++++++++---------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index 1b5f8509559..17a8f0f1144 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -160,9 +160,6 @@ function getCustParams(bid, options) { 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 }, optCustParams, ); return encodeURIComponent(formatQS(customParams)); diff --git a/src/auction.js b/src/auction.js index 96c59f43eef..0ddb2450561 100644 --- a/src/auction.js +++ b/src/auction.js @@ -386,6 +386,10 @@ export function doCallbacksIfTimedout(auctionInstance, bidResponse) { // Add a bid to the auction. export function addBidToAuction(auctionInstance, 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); @@ -429,6 +433,7 @@ export const callPrebidCache = hook('async', function(auctionInstance, bidRespon doCallbacksIfTimedout(auctionInstance, bidResponse); } else { bidResponse.videoCacheKey = cacheIds[0].uuid; + if (!bidResponse.vastUrl) { bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey); } @@ -485,16 +490,24 @@ 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, 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); } - // use any targeting provided as defaults, otherwise just set from getKeyValueTargetingPairs - bidObject.adserverTargeting = Object.assign(bidObject.adserverTargeting || {}, keyValues); + let cacheTargetKeys = {}; + if (bidObject.videoCacheKey) { + cacheTargetKeys.hb_uuid = bidObject.videoCacheKey; + cacheTargetKeys.hb_cache_id = bidObject.videoCacheKey; + } - return bidObject; + // use any targeting provided as defaults, otherwise just set from getKeyValueTargetingPairs + bidObject.adserverTargeting = Object.assign(bidObject.adserverTargeting || {}, cacheTargetKeys, keyValues); } export function getStandardBidderSettings(mediaType) { 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({