Skip to content

Commit 4346aa8

Browse files
authored
Prebid Core: Addition of Optional Category Targeting Key (prebid#9268)
* addition of category optional targeting * removed console log statements * console.log statements for debugging * updated tests * formatting changes * added pbs test
1 parent 1b4d83c commit 4346aa8

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/auction.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,16 @@ export const getAdvertiserDomain = () => {
828828
}
829829
}
830830

831+
/**
832+
* This function returns a function to get the primary category id from bid response meta
833+
* @returns {function}
834+
*/
835+
export const getPrimaryCatId = () => {
836+
return (bid) => {
837+
return (bid.meta && bid.meta.primaryCatId) ? bid.meta.primaryCatId : '';
838+
}
839+
}
840+
831841
// factory for key value objs
832842
function createKeyVal(key, value) {
833843
return {
@@ -853,6 +863,7 @@ function defaultAdserverTargeting() {
853863
createKeyVal(TARGETING_KEYS.SOURCE, 'source'),
854864
createKeyVal(TARGETING_KEYS.FORMAT, 'mediaType'),
855865
createKeyVal(TARGETING_KEYS.ADOMAIN, getAdvertiserDomain()),
866+
createKeyVal(TARGETING_KEYS.ACAT, getPrimaryCatId()),
856867
]
857868
}
858869

@@ -865,7 +876,6 @@ function defaultAdserverTargeting() {
865876
export function getStandardBidderSettings(mediaType, bidderCode) {
866877
const TARGETING_KEYS = CONSTANTS.TARGETING_KEYS;
867878
const standardSettings = Object.assign({}, bidderSettings.settingsFor(null));
868-
869879
if (!standardSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) {
870880
standardSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = defaultAdserverTargeting();
871881
}

src/constants.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"UUID": "hb_uuid",
7777
"CACHE_ID": "hb_cache_id",
7878
"CACHE_HOST": "hb_cache_host",
79-
"ADOMAIN": "hb_adomain"
79+
"ADOMAIN": "hb_adomain",
80+
"ACAT": "hb_acat"
8081
},
8182
"DEFAULT_TARGETING_KEYS": {
8283
"BIDDER": "hb_bidder",

test/spec/auctionmanager_spec.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ describe('auctionmanager.js', function () {
186186
source: 'client',
187187
mediaType: 'banner',
188188
meta: {
189-
advertiserDomains: ['adomain']
189+
advertiserDomains: ['adomain'],
190+
primaryCatId: 'IAB-test'
190191
}
191192
};
192193

@@ -200,6 +201,7 @@ describe('auctionmanager.js', function () {
200201
expected[ CONSTANTS.TARGETING_KEYS.SOURCE ] = bid.source;
201202
expected[ CONSTANTS.TARGETING_KEYS.FORMAT ] = bid.mediaType;
202203
expected[ CONSTANTS.TARGETING_KEYS.ADOMAIN ] = bid.meta.advertiserDomains[0];
204+
expected[ CONSTANTS.TARGETING_KEYS.ACAT ] = bid.meta.primaryCatId;
203205
if (bid.mediaType === 'video') {
204206
expected[ CONSTANTS.TARGETING_KEYS.UUID ] = bid.videoCacheKey;
205207
expected[ CONSTANTS.TARGETING_KEYS.CACHE_ID ] = bid.videoCacheKey;
@@ -290,6 +292,12 @@ describe('auctionmanager.js', function () {
290292
val: function (bidResponse) {
291293
return bidResponse.meta.advertiserDomains[0];
292294
}
295+
},
296+
{
297+
key: CONSTANTS.TARGETING_KEYS.ACAT,
298+
val: function (bidResponse) {
299+
return bidResponse.meta.primaryCatId;
300+
}
293301
}
294302
]
295303

@@ -367,6 +375,12 @@ describe('auctionmanager.js', function () {
367375
val: function (bidResponse) {
368376
return bidResponse.meta.advertiserDomains[0];
369377
}
378+
},
379+
{
380+
key: CONSTANTS.TARGETING_KEYS.ACAT,
381+
val: function (bidResponse) {
382+
return bidResponse.meta.primaryCatId;
383+
}
370384
}
371385
]
372386

@@ -455,6 +469,24 @@ describe('auctionmanager.js', function () {
455469
assert.deepEqual(response, expected);
456470
});
457471

472+
it('Should set targeting as expecting when pbs is enabled', function () {
473+
config.setConfig({
474+
s2sConfig: {
475+
accountId: '1',
476+
enabled: true,
477+
defaultVendor: 'appnexus',
478+
bidders: ['appnexus'],
479+
timeout: 1000,
480+
adapter: 'prebidServer'
481+
}
482+
});
483+
484+
$$PREBID_GLOBAL$$.bidderSettings = {};
485+
let expected = getDefaultExpected(bid);
486+
let response = getKeyValueTargetingPairs(bid.bidderCode, bid);
487+
assert.deepEqual(response, expected);
488+
});
489+
458490
it('Custom bidCpmAdjustment for one bidder and inherit standard but doesn\'t use standard bidCpmAdjustment', function () {
459491
$$PREBID_GLOBAL$$.bidderSettings =
460492
{

0 commit comments

Comments
 (0)