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

fix two issues related to hb_uuid and hb_cache_id targeting keys #3605

Merged
merged 7 commits into from
Mar 4, 2019
3 changes: 0 additions & 3 deletions modules/dfpAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ function getCustParams(bid, options) {
let customParams = Object.assign({},
allTargetingData,
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));
Expand Down
23 changes: 18 additions & 5 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ export function doCallbacksIfTimedout(auctionInstance, bidResponse) {

// Add a bid to the auction.
export function addBidToAuction(auctionInstance, bidResponse) {
let bidderRequests = auctionInstance.getBidRequests();
let bidderRequest = find(bidderRequests, bidderRequest => bidderRequest.bidderCode === bidResponse.bidderCode);
setupBidTargeting(bidResponse, bidderRequest);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling this function for all formats ? We need hb_uuid and hb_cache_id only when cache is done i.e only for video as of now. Won't it be easier if we attach after hook function to callPrebidCache. That way these two targeting keys will only be added if we do caching.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's not exclusively used by the cache related keys; it sets up all the targeting for the bid object.


events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bidResponse);
auctionInstance.addBidReceived(bidResponse);

Expand Down Expand Up @@ -429,6 +433,7 @@ export const callPrebidCache = hook('async', function(auctionInstance, bidRespon
doCallbacksIfTimedout(auctionInstance, bidResponse);
} else {
bidResponse.videoCacheKey = cacheIds[0].uuid;

if (!bidResponse.vastUrl) {
bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey);
}
Expand Down Expand Up @@ -485,16 +490,24 @@ function getPreparedBidForAuction({adUnitCode, bid, bidderRequest, auctionId}) {
bidObject.pbDg = priceStringsObj.dense;
bidObject.pbCg = priceStringsObj.custom;

// if there is any key value pairs to map do here
var keyValues;
return bidObject;
}

function setupBidTargeting(bidObject, bidderRequest) {
let keyValues;
if (bidObject.bidderCode && (bidObject.cpm > 0 || bidObject.dealId)) {
let bidReq = find(bidderRequest.bids, bid => bid.adUnitCode === bidObject.adUnitCode);
keyValues = getKeyValueTargetingPairs(bidObject.bidderCode, bidObject, bidReq);
}

// use any targeting provided as defaults, otherwise just set from getKeyValueTargetingPairs
bidObject.adserverTargeting = Object.assign(bidObject.adserverTargeting || {}, keyValues);
let cacheTargetKeys = {};
if (bidObject.videoCacheKey) {
cacheTargetKeys.hb_uuid = bidObject.videoCacheKey;
cacheTargetKeys.hb_cache_id = bidObject.videoCacheKey;
}

return bidObject;
// use any targeting provided as defaults, otherwise just set from getKeyValueTargetingPairs
bidObject.adserverTargeting = Object.assign(bidObject.adserverTargeting || {}, cacheTargetKeys, keyValues);
}

export function getStandardBidderSettings(mediaType) {
Expand Down
33 changes: 18 additions & 15 deletions test/spec/modules/dfpAdServerVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { targeting } from 'src/targeting';

const bid = {
videoCacheKey: 'abc',
adserverTargeting: { },
adserverTargeting: {
hb_uuid: 'abc',
hb_cache_id: 'abc',
},
};

describe('The DFP video support module', function () {
Expand Down Expand Up @@ -40,7 +43,7 @@ describe('The DFP video support module', function () {
});

it('can take an adserver url as a parameter', function () {
const bidCopy = Object.assign({ }, bid);
const bidCopy = utils.deepClone(bid);
bidCopy.vastUrl = 'vastUrl.example';

const url = parse(buildDfpVideoUrl({
Expand Down Expand Up @@ -90,10 +93,10 @@ describe('The DFP video support module', function () {
});

it('should include the cache key and adserver targeting in cust_params', function () {
const bidCopy = Object.assign({ }, bid);
bidCopy.adserverTargeting = {
const bidCopy = utils.deepClone(bid);
bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, {
hb_adid: 'ad_id',
};
});

const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
Expand Down Expand Up @@ -160,10 +163,10 @@ describe('The DFP video support module', function () {
}
});

const bidCopy = Object.assign({ }, bid);
bidCopy.adserverTargeting = {
const bidCopy = utils.deepClone(bid);
bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, {
hb_adid: 'ad_id',
};
});

const url = parse(buildDfpVideoUrl({
adUnit: adUnitsCopy,
Expand All @@ -184,10 +187,10 @@ describe('The DFP video support module', function () {
});

it('should merge the user-provided cust_params with the default ones', function () {
const bidCopy = Object.assign({ }, bid);
bidCopy.adserverTargeting = {
const bidCopy = utils.deepClone(bid);
bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, {
hb_adid: 'ad_id',
};
});

const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
Expand All @@ -207,10 +210,10 @@ describe('The DFP video support module', function () {
});

it('should merge the user-provided cust-params with the default ones when using url object', function () {
const bidCopy = Object.assign({ }, bid);
bidCopy.adserverTargeting = {
const bidCopy = utils.deepClone(bid);
bidCopy.adserverTargeting = Object.assign(bidCopy.adserverTargeting, {
hb_adid: 'ad_id',
};
});

const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
Expand All @@ -229,7 +232,7 @@ describe('The DFP video support module', function () {
});

it('should not overwrite an existing description_url for object input and cache disabled', function () {
const bidCopy = Object.assign({}, bid);
const bidCopy = utils.deepClone(bid);
bidCopy.vastUrl = 'vastUrl.example';

const url = parse(buildDfpVideoUrl({
Expand Down