Skip to content

Commit

Permalink
Add Adomain Targeting Key and Default Targeting Keys (prebid#6116)
Browse files Browse the repository at this point in the history
* Add Adomain Targeting Key

* add default targeting key

Co-authored-by: Veronica Kim <vkim@vkim-mac.lan>
  • Loading branch information
2 people authored and stsepelin committed May 28, 2021
1 parent 8ed9d6a commit 633d175
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
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

0 comments on commit 633d175

Please sign in to comment.