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

Making targeting keys configurable #3140

Merged
merged 20 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
16 changes: 8 additions & 8 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,17 @@ export function getStandardBidderSettings(mediaType) {
if (!bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) {
bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = [
{
key: 'hb_bidder',
key: CONSTANTS.TARGETING_KEYS.BIDDER,
val: function (bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: 'hb_adid',
key: CONSTANTS.TARGETING_KEYS.AD_ID,
val: function (bidResponse) {
return bidResponse.adId;
}
}, {
key: 'hb_pb',
key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET,
val: function (bidResponse) {
if (granularity === CONSTANTS.GRANULARITY_OPTIONS.AUTO) {
return bidResponse.pbAg;
Expand All @@ -483,24 +483,24 @@ export function getStandardBidderSettings(mediaType) {
}
}
}, {
key: 'hb_size',
key: CONSTANTS.TARGETING_KEYS.SIZE,
val: function (bidResponse) {
return bidResponse.size;
}
}, {
key: 'hb_deal',
key: CONSTANTS.TARGETING_KEYS.DEAL,
val: function (bidResponse) {
return bidResponse.dealId;
}
},
{
key: 'hb_source',
key: CONSTANTS.TARGETING_KEYS.SOURCE,
val: function (bidResponse) {
return bidResponse.source;
}
},
{
key: 'hb_format',
key: CONSTANTS.TARGETING_KEYS.FORMAT,
val: function (bidResponse) {
return bidResponse.mediaType;
}
Expand Down Expand Up @@ -561,7 +561,7 @@ function setKeys(keyValues, bidderSettings, custBidObj) {

if (
((typeof bidderSettings.suppressEmptyKeys !== 'undefined' && bidderSettings.suppressEmptyKeys === true) ||
key === 'hb_deal') && // hb_deal is suppressed automatically if not set
key === CONSTANTS.TARGETING_KEYS.DEAL) && // hb_deal is suppressed automatically if not set
(
utils.isEmptyStr(value) ||
value === null ||
Expand Down
27 changes: 18 additions & 9 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,24 @@
"DENSE": "dense",
"CUSTOM": "custom"
},
"TARGETING_KEYS": [
"hb_bidder",
"hb_adid",
"hb_pb",
"hb_size",
"hb_deal",
"hb_source",
"hb_format"
],
"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"
},
"NATIVE_KEYS": {
"title": "hb_native_title",
"body": "hb_native_body",
"sponsoredBy": "hb_native_brand",
"image": "hb_native_image",
"icon": "hb_native_icon",
"clickUrl": "hb_native_linkurl",
"cta": "hb_native_cta"
},
"S2S" : {
"SRC" : "s2s",
"DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/openrtb2/auction",
Expand Down
18 changes: 5 additions & 13 deletions src/native.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { deepAccess, getBidRequest, logError, triggerPixel, insertHtmlIntoIframe } from './utils';
import includes from 'core-js/library/fn/array/includes';

export const nativeAdapters = [];
const CONSTANTS = require('./constants.json');

export const NATIVE_KEYS = {
title: 'hb_native_title',
body: 'hb_native_body',
sponsoredBy: 'hb_native_brand',
image: 'hb_native_image',
icon: 'hb_native_icon',
clickUrl: 'hb_native_linkurl',
cta: 'hb_native_cta',
};
export const nativeAdapters = [];

export const NATIVE_TARGETING_KEYS = Object.keys(NATIVE_KEYS).map(
key => NATIVE_KEYS[key]
export const NATIVE_TARGETING_KEYS = Object.keys(CONSTANTS.NATIVE_KEYS).map(
key => CONSTANTS.NATIVE_KEYS[key]
);
harpere marked this conversation as resolved.
Show resolved Hide resolved

const IMAGE = {
Expand Down Expand Up @@ -163,7 +155,7 @@ export function getNativeTargeting(bid) {
let keyValues = {};

Object.keys(bid['native']).forEach(asset => {
const key = NATIVE_KEYS[asset];
const key = CONSTANTS.NATIVE_KEYS[asset];
let value = bid['native'][asset];

// native image-type assets can be a string or an object with a url prop
Expand Down
10 changes: 7 additions & 3 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const RENDERED = 'rendered';
const MAX_DFP_KEYLENGTH = 20;
const TTL_BUFFER = 1000;

export const TARGETING_KEYS = Object.keys(CONSTANTS.TARGETING_KEYS).map(
key => CONSTANTS.TARGETING_KEYS[key]
);

harpere marked this conversation as resolved.
Show resolved Hide resolved
// return unexpired bids
export const isBidNotExpired = (bid) => (bid.responseTimestamp + bid.ttl * 1000 + TTL_BUFFER) > timestamp();

Expand Down Expand Up @@ -262,7 +266,7 @@ export function newTargeting(auctionManager) {
.reduce((acc, key) => {
const targetingValue = [winner.adserverTargeting[key]];
const targeting = { [key.substring(0, MAX_DFP_KEYLENGTH)]: targetingValue };
if (key === 'hb_deal') {
if (key === CONSTANTS.TARGETING_KEYS.DEAL) {
const bidderCodeTargetingKey = `${key}_${winner.bidderCode}`.substring(0, MAX_DFP_KEYLENGTH);
const bidderCodeTargeting = { [bidderCodeTargetingKey]: targetingValue };
return [...acc, targeting, bidderCodeTargeting];
Expand All @@ -278,7 +282,7 @@ export function newTargeting(auctionManager) {
function getStandardKeys() {
return auctionManager.getStandardBidderAdServerTargeting() // in case using a custom standard key set
.map(targeting => targeting.key)
.concat(CONSTANTS.TARGETING_KEYS).filter(uniques); // standard keys defined in the library.
.concat(TARGETING_KEYS).filter(uniques); // standard keys defined in the library.
}

/**
Expand Down Expand Up @@ -360,7 +364,7 @@ export function newTargeting(auctionManager) {
* @return {targetingArray} all non-winning bids targeting
*/
function getBidLandscapeTargeting(adUnitCodes, bidsReceived) {
const standardKeys = CONSTANTS.TARGETING_KEYS.concat(NATIVE_TARGETING_KEYS);
const standardKeys = TARGETING_KEYS.concat(NATIVE_TARGETING_KEYS);

const bids = getHighestCpmBidsFromBidPool(bidsReceived, getHighestCpm);

Expand Down
Loading