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

Prebid Core: Addition of Optional Category Targeting Key #9268

Merged
merged 6 commits into from
Dec 8, 2022
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
12 changes: 11 additions & 1 deletion src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,16 @@ export const getAdvertiserDomain = () => {
}
}

/**
* This function returns a function to get the primary category id from bid response meta
* @returns {function}
*/
export const getPrimaryCatId = () => {
return (bid) => {
return (bid.meta && bid.meta.primaryCatId) ? bid.meta.primaryCatId : '';
}
}

// factory for key value objs
function createKeyVal(key, value) {
return {
Expand All @@ -837,6 +847,7 @@ function defaultAdserverTargeting() {
createKeyVal(TARGETING_KEYS.SOURCE, 'source'),
createKeyVal(TARGETING_KEYS.FORMAT, 'mediaType'),
createKeyVal(TARGETING_KEYS.ADOMAIN, getAdvertiserDomain()),
createKeyVal(TARGETING_KEYS.ACAT, getPrimaryCatId()),
]
}

Expand All @@ -849,7 +860,6 @@ function defaultAdserverTargeting() {
export function getStandardBidderSettings(mediaType, bidderCode) {
const TARGETING_KEYS = CONSTANTS.TARGETING_KEYS;
const standardSettings = Object.assign({}, bidderSettings.settingsFor(null));

if (!standardSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) {
standardSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = defaultAdserverTargeting();
}
Expand Down
3 changes: 2 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"UUID": "hb_uuid",
"CACHE_ID": "hb_cache_id",
"CACHE_HOST": "hb_cache_host",
"ADOMAIN": "hb_adomain"
"ADOMAIN": "hb_adomain",
"ACAT": "hb_acat"
},
"DEFAULT_TARGETING_KEYS": {
"BIDDER": "hb_bidder",
Expand Down
34 changes: 33 additions & 1 deletion test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ describe('auctionmanager.js', function () {
source: 'client',
mediaType: 'banner',
meta: {
advertiserDomains: ['adomain']
advertiserDomains: ['adomain'],
primaryCatId: 'IAB-test'
}
};

Expand All @@ -199,6 +200,7 @@ describe('auctionmanager.js', function () {
expected[ CONSTANTS.TARGETING_KEYS.SOURCE ] = bid.source;
expected[ CONSTANTS.TARGETING_KEYS.FORMAT ] = bid.mediaType;
expected[ CONSTANTS.TARGETING_KEYS.ADOMAIN ] = bid.meta.advertiserDomains[0];
expected[ CONSTANTS.TARGETING_KEYS.ACAT ] = bid.meta.primaryCatId;
if (bid.mediaType === 'video') {
expected[ CONSTANTS.TARGETING_KEYS.UUID ] = bid.videoCacheKey;
expected[ CONSTANTS.TARGETING_KEYS.CACHE_ID ] = bid.videoCacheKey;
Expand Down Expand Up @@ -289,6 +291,12 @@ describe('auctionmanager.js', function () {
val: function (bidResponse) {
return bidResponse.meta.advertiserDomains[0];
}
},
{
key: CONSTANTS.TARGETING_KEYS.ACAT,
val: function (bidResponse) {
return bidResponse.meta.primaryCatId;
}
}
]

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

Expand Down Expand Up @@ -454,6 +468,24 @@ describe('auctionmanager.js', function () {
assert.deepEqual(response, expected);
});

it('Should set targeting as expecting when pbs is enabled', function () {
config.setConfig({
s2sConfig: {
accountId: '1',
enabled: true,
defaultVendor: 'appnexus',
bidders: ['appnexus'],
timeout: 1000,
adapter: 'prebidServer'
}
});

$$PREBID_GLOBAL$$.bidderSettings = {};
let expected = getDefaultExpected(bid);
let response = getKeyValueTargetingPairs(bid.bidderCode, bid);
assert.deepEqual(response, expected);
});

it('Custom bidCpmAdjustment for one bidder and inherit standard but doesn\'t use standard bidCpmAdjustment', function () {
$$PREBID_GLOBAL$$.bidderSettings =
{
Expand Down