From b3a4e739f52ac14f7bacd59ebb4b57557318bbf5 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Wed, 9 Mar 2022 18:09:34 -0300 Subject: [PATCH 1/5] original url components take precedence over defaults uses object assignment --- modules/dfpAdServerVideo.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index 2dfd9ea4386..55de8ad5a12 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -111,12 +111,11 @@ export function buildDfpVideoUrl(options) { const uspConsent = uspDataHandler.getConsentData(); if (uspConsent) { queryParams.us_privacy = uspConsent; } - return buildUrl({ + return buildUrl(Object.assign({ protocol: 'https', host: 'securepubads.g.doubleclick.net', - pathname: '/gampad/ads', - search: queryParams - }); + pathname: '/gampad/ads' + }, urlComponents, { search: queryParams })); } export function notifyTranslationModule(fn) { From 97283bf3bd73b3090864299a04048847e306e336 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Thu, 10 Mar 2022 14:33:24 -0300 Subject: [PATCH 2/5] tests that url is respected --- test/spec/modules/dfpAdServerVideo_spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/spec/modules/dfpAdServerVideo_spec.js b/test/spec/modules/dfpAdServerVideo_spec.js index eaffca01e06..1a788e28a79 100644 --- a/test/spec/modules/dfpAdServerVideo_spec.js +++ b/test/spec/modules/dfpAdServerVideo_spec.js @@ -410,6 +410,23 @@ describe('The DFP video support module', function () { expect(customParams).to.have.property('hb_cache_id', 'def'); }); + it('should keep the url protocol, host, and pathname when using url and params', function () { + const url = parse(buildDfpVideoUrl({ + adUnit: adUnit, + bid: bid, + url: 'http://video.adserver.example/ads?sz=640x480&iu=/123/aduniturl&impl=s', + params: { + cust_params: { + hb_rand: 'random' + } + } + })); + + expect(url.protocol).to.equal('http:'); + expect(url.host).to.equal('video.adserver.example'); + expect(url.pathname).to.equal('/ads'); + }); + describe('adpod unit tests', function () { let amStub; let amGetAdUnitsStub; From 5bd3f2d799371fe75e8b1eb53c5e4a602ea48e83 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Fri, 11 Mar 2022 19:42:33 -0300 Subject: [PATCH 3/5] respects url size and cust params --- modules/dfpAdServerVideo.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index 55de8ad5a12..0714ed03ac9 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -88,7 +88,18 @@ export function buildDfpVideoUrl(options) { sz: parseSizesInput(deepAccess(adUnit, 'mediaTypes.video.playerSize')).join('|'), url: encodeURIComponent(location.href), }; - const encodedCustomParams = getCustParams(bid, options); + + const urlSearchComponent = urlComponents.search; + const urlSzParam = urlSearchComponent && urlSearchComponent.sz + if (urlSzParam) { + derivedParams.sz = urlSzParam + '|' + derivedParams.sz; + } + + let encodedCustomParams = getCustParams(bid, options); + const urlCustParams = urlSearchComponent.cust_params; + if (urlCustParams) { + encodedCustomParams = urlCustParams + '%26' + encodedCustomParams; + } const queryParams = Object.assign({}, defaultParamConstants, @@ -228,7 +239,6 @@ function buildUrlFromAdserverUrlComponents(components, bid, options) { const encodedCustomParams = getCustParams(bid, options); components.search.cust_params = (components.search.cust_params) ? components.search.cust_params + '%26' + encodedCustomParams : encodedCustomParams; - return buildUrl(components); } From 16a461fecbd2d4bb749f7db321c5fa06be26da33 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Wed, 16 Mar 2022 16:39:24 -0300 Subject: [PATCH 4/5] moves url cust param addition to fn --- modules/dfpAdServerVideo.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index 0714ed03ac9..7f8ad3351fa 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -95,11 +95,7 @@ export function buildDfpVideoUrl(options) { derivedParams.sz = urlSzParam + '|' + derivedParams.sz; } - let encodedCustomParams = getCustParams(bid, options); - const urlCustParams = urlSearchComponent.cust_params; - if (urlCustParams) { - encodedCustomParams = urlCustParams + '%26' + encodedCustomParams; - } + let encodedCustomParams = getCustParams(bid, options, urlSearchComponent && urlSearchComponent.cust_params); const queryParams = Object.assign({}, defaultParamConstants, @@ -237,8 +233,7 @@ function buildUrlFromAdserverUrlComponents(components, bid, options) { const descriptionUrl = getDescriptionUrl(bid, components, 'search'); if (descriptionUrl) { components.search.description_url = descriptionUrl; } - const encodedCustomParams = getCustParams(bid, options); - components.search.cust_params = (components.search.cust_params) ? components.search.cust_params + '%26' + encodedCustomParams : encodedCustomParams; + components.search.cust_params = getCustParams(bid, options, components.search.cust_params); return buildUrl(components); } @@ -267,7 +262,7 @@ function getDescriptionUrl(bid, components, prop) { * @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) { +function getCustParams(bid, options, urlCustParams) { const adserverTargeting = (bid && bid.adserverTargeting) || {}; let allTargetingData = {}; @@ -290,7 +285,12 @@ function getCustParams(bid, options) { // merge the prebid + publisher targeting sets const publisherTargetingSet = deepAccess(options, 'params.cust_params'); const targetingSet = Object.assign({}, prebidTargetingSet, publisherTargetingSet); - return encodeURIComponent(formatQS(targetingSet)); + let encodedParams = encodeURIComponent(formatQS(targetingSet)); + if (urlCustParams) { + encodedParams = urlCustParams + '%26' + encodedParams; + } + + return encodedParams; } registerVideoSupport('dfp', { From 52a36b0c249b88c931027924711e670bd3af33ad Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Wed, 16 Mar 2022 17:10:19 -0300 Subject: [PATCH 5/5] tests that url params are respected --- test/spec/modules/dfpAdServerVideo_spec.js | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/spec/modules/dfpAdServerVideo_spec.js b/test/spec/modules/dfpAdServerVideo_spec.js index 1a788e28a79..300e2104fae 100644 --- a/test/spec/modules/dfpAdServerVideo_spec.js +++ b/test/spec/modules/dfpAdServerVideo_spec.js @@ -427,6 +427,42 @@ describe('The DFP video support module', function () { expect(url.pathname).to.equal('/ads'); }); + it('should append to the url size param', () => { + const url = parse(buildDfpVideoUrl({ + adUnit: adUnit, + bid: bid, + url: 'http://video.adserver.example/ads?sz=360x240&iu=/123/aduniturl&impl=s', + params: { + cust_params: { + hb_rand: 'random' + } + } + })); + + const queryObject = utils.parseQS(url.query); + expect(queryObject.sz).to.equal('360x240|640x480'); + }); + + it('should append to the existing url cust params', () => { + const url = parse(buildDfpVideoUrl({ + adUnit: adUnit, + bid: bid, + url: 'http://video.adserver.example/ads?sz=360x240&iu=/123/aduniturl&impl=s&cust_params=existing_key%3Dexisting_value%26other_key%3Dother_value', + params: { + cust_params: { + hb_rand: 'random' + } + } + })); + + const queryObject = utils.parseQS(url.query); + const customParams = utils.parseQS('?' + decodeURIComponent(queryObject.cust_params)); + + expect(customParams).to.have.property('existing_key', 'existing_value'); + expect(customParams).to.have.property('other_key', 'other_value'); + expect(customParams).to.have.property('hb_rand', 'random'); + }); + describe('adpod unit tests', function () { let amStub; let amGetAdUnitsStub;