Skip to content

Commit

Permalink
fixes #2353 - not appending hb_uuid and hb_cache_id
Browse files Browse the repository at this point in the history
  • Loading branch information
mkendall07 committed Apr 5, 2018
1 parent 229ffa6 commit 8c29d2b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
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

0 comments on commit 8c29d2b

Please sign in to comment.