Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFP Ad Server Video: respect original url #8168

Merged
merged 5 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions modules/dfpAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ 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, urlSearchComponent && urlSearchComponent.cust_params);

const queryParams = Object.assign({},
defaultParamConstants,
Expand All @@ -111,12 +118,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) {
Expand Down Expand Up @@ -227,9 +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);
}

Expand Down Expand Up @@ -258,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 = {};
Expand All @@ -281,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', {
Expand Down
53 changes: 53 additions & 0 deletions test/spec/modules/dfpAdServerVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,59 @@ 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');
});

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;
Expand Down