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

Add Adomain Targeting Key and Default Targeting Keys #6116

Merged
merged 3 commits into from
Jan 14, 2021
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
11 changes: 11 additions & 0 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,16 @@ export const getPriceByGranularity = (granularity) => {
}
}

/**
* This function returns a function to get first advertiser domain from bid response meta
* @returns {function}
*/
export const getAdvertiserDomain = () => {
return (bid) => {
return (bid.meta && bid.meta.advertiserDomains && bid.meta.advertiserDomains.length > 0) ? bid.meta.advertiserDomains[0] : '';
}
}

/**
* @param {string} mediaType
* @param {string} bidderCode
Expand Down Expand Up @@ -662,6 +672,7 @@ export function getStandardBidderSettings(mediaType, bidderCode, bidReq) {
createKeyVal(TARGETING_KEYS.DEAL, 'dealId'),
createKeyVal(TARGETING_KEYS.SOURCE, 'source'),
createKeyVal(TARGETING_KEYS.FORMAT, 'mediaType'),
createKeyVal(TARGETING_KEYS.ADOMAIN, getAdvertiserDomain()),
]
}

Expand Down
13 changes: 13 additions & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@
"CUSTOM": "custom"
},
"TARGETING_KEYS": {
"BIDDER": "hb_bidder",
"AD_ID": "hb_adid",
"PRICE_BUCKET": "hb_pb",
"SIZE": "hb_size",
"DEAL": "hb_deal",
"SOURCE": "hb_source",
"FORMAT": "hb_format",
"UUID": "hb_uuid",
"CACHE_ID": "hb_cache_id",
"CACHE_HOST": "hb_cache_host",
"ADOMAIN" : "hb_adomain"
},
"DEFAULT_TARGETING_KEYS": {
"BIDDER": "hb_bidder",
"AD_ID": "hb_adid",
"PRICE_BUCKET": "hb_pb",
Expand Down
3 changes: 2 additions & 1 deletion src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ export function newTargeting(auctionManager) {
});
});

const allowedKeys = config.getConfig('targetingControls.allowTargetingKeys');
const defaultKeys = Object.keys(Object.assign({}, CONSTANTS.DEFAULT_TARGETING_KEYS, CONSTANTS.NATIVE_KEYS));
const allowedKeys = config.getConfig('targetingControls.allowTargetingKeys') || defaultKeys;
if (Array.isArray(allowedKeys) && allowedKeys.length > 0) {
targeting = getAllowedTargetingKeyValues(targeting, allowedKeys);
}
Expand Down
16 changes: 16 additions & 0 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ describe('auctionmanager.js', function () {
adId: '1adId',
source: 'client',
mediaType: 'banner',
meta: {
advertiserDomains: ['adomain']
}
};

/* return the expected response for a given bid, filter by keys if given */
Expand All @@ -154,6 +157,7 @@ describe('auctionmanager.js', function () {
expected[ CONSTANTS.TARGETING_KEYS.SIZE ] = bid.getSize();
expected[ CONSTANTS.TARGETING_KEYS.SOURCE ] = bid.source;
expected[ CONSTANTS.TARGETING_KEYS.FORMAT ] = bid.mediaType;
expected[ CONSTANTS.TARGETING_KEYS.ADOMAIN ] = bid.meta.advertiserDomains[0];
if (bid.mediaType === 'video') {
expected[ CONSTANTS.TARGETING_KEYS.UUID ] = bid.videoCacheKey;
expected[ CONSTANTS.TARGETING_KEYS.CACHE_ID ] = bid.videoCacheKey;
Expand Down Expand Up @@ -239,6 +243,12 @@ describe('auctionmanager.js', function () {
return bidResponse.mediaType;
}
},
{
key: CONSTANTS.TARGETING_KEYS.ADOMAIN,
val: function (bidResponse) {
return bidResponse.meta.advertiserDomains[0];
}
}
]

}
Expand Down Expand Up @@ -309,6 +319,12 @@ describe('auctionmanager.js', function () {
val: function (bidResponse) {
return bidResponse.videoCacheKey;
}
},
{
key: CONSTANTS.TARGETING_KEYS.ADOMAIN,
val: function (bidResponse) {
return bidResponse.meta.advertiserDomains[0];
}
}
]

Expand Down