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

fixes #2353 - not appending hb_uuid and hb_cache_id #2363

Merged
merged 1 commit into from
Apr 13, 2018
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
37 changes: 22 additions & 15 deletions modules/dfpAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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
});
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down
2 changes: 2 additions & 0 deletions test/spec/modules/dfpAdServerVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down