diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index cc285ca4aa7..d1c66833104 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -82,22 +82,14 @@ export default function buildDfpVideoUrl(options) { sz: parseSizesInput(adUnit.sizes).join('|'), url: location.href, }; - - const adserverTargeting = (bid && bid.adserverTargeting) || {}; - - const customParams = Object.assign({}, - adserverTargeting, - { hb_uuid: bid && bid.videoCacheKey }, - // hb_uuid will be deprecated and replaced by hb_cache_id - {hb_cache_id: bid && bid.videoCacheKey}, - options.params.cust_params); + const encodedCustomParams = getCustParams(bid, options); const queryParams = Object.assign({}, defaultParamConstants, urlComponents.search, derivedParams, options.params, - { cust_params: encodeURIComponent(formatQS(customParams)) } + { cust_params: encodedCustomParams } ); const descriptionUrl = getDescriptionUrl(bid, options, 'params'); @@ -122,11 +114,7 @@ function buildUrlFromAdserverUrlComponents(components, bid) { const descriptionUrl = getDescriptionUrl(bid, components, 'search'); if (descriptionUrl) { components.search.description_url = descriptionUrl; } - const adserverTargeting = (bid && bid.adserverTargeting) || {}; - const customParams = Object.assign({}, - adserverTargeting, - ); - const encodedCustomParams = encodeURIComponent(formatQS(customParams)); + const encodedCustomParams = getCustParams(bid); components.search.cust_params = (components.search.cust_params) ? components.search.cust_params + '%26' + encodedCustomParams : encodedCustomParams; return buildUrl(components); @@ -151,6 +139,25 @@ function getDescriptionUrl(bid, components, prop) { } } +/** + * Returns the encoded `cust_params` from the bid.adserverTargeting and adds the `hb_uuid`, and `hb_cache_id`. Optionally the options.params.cust_params + * @param {AdapterBidResponse} bid + * @param {Object} options this is the options passed in from the `buildDfpVideoUrl` function + * @return {Object} Encoded key value pairs for cust_params + */ +function getCustParams(bid, options) { + const adserverTargeting = (bid && bid.adserverTargeting) || {}; + const optCustParams = deepAccess(options, 'params.cust_params'); + let customParams = Object.assign({}, + 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)); +} + registerVideoSupport('dfp', { buildVideoUrl: buildDfpVideoUrl }); diff --git a/src/utils.js b/src/utils.js index 701fd37115a..b192cf2fef6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -775,6 +775,9 @@ export function groupBy(xs, key) { * @returns {*} The value found at the specified object path, or undefined if path is not found. */ export function deepAccess(obj, path) { + if (!obj) { + return; + } path = String(path).split('.'); for (let i = 0; i < path.length; i++) { obj = obj[path[i]]; diff --git a/test/spec/modules/dfpAdServerVideo_spec.js b/test/spec/modules/dfpAdServerVideo_spec.js index be51953169c..c4a799b0b0a 100644 --- a/test/spec/modules/dfpAdServerVideo_spec.js +++ b/test/spec/modules/dfpAdServerVideo_spec.js @@ -148,6 +148,8 @@ describe('The DFP video support module', () => { expect(customParams).to.have.property('hb_adid', 'ad_id'); expect(customParams).to.have.property('section', 'blog'); expect(customParams).to.have.property('mykey', 'myvalue'); + expect(customParams).to.have.property('hb_uuid', 'abc'); + expect(customParams).to.have.property('hb_cache_id', 'abc'); }); it('should not overwrite an existing description_url for object input and cache disabled', () => {