-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Rubicon Bid Adapter FPD Update #6122
Changes from 2 commits
7680ffc
924fc81
5780fd4
c8bd004
030da98
330dbe3
151b55b
21a2471
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,11 +255,11 @@ export const spec = { | |
} | ||
|
||
const bidFpd = { | ||
user: bidRequest.params.visitor || {}, | ||
context: bidRequest.params.inventory || {} | ||
user: {...bidRequest.params.visitor} || {}, | ||
context: {...bidRequest.params.inventory} || {} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also place lines 257 - 262 into applyFpd function? save a couple duplicate names. |
||
|
||
if (bidRequest.params.keywords) bidFpd.context.keywords = bidRequest.params.keywords; | ||
if (bidRequest.params.keywords) bidFpd.context.keywords = (utils.isArray(bidRequest.params.keywords)) ? bidRequest.params.keywords.join(',') : bidRequest.params.keywords; | ||
|
||
applyFPD(utils.mergeDeep({}, config.getConfig('fpd') || {}, bidRequest.fpd || {}, bidFpd), VIDEO, data); | ||
|
||
|
@@ -516,11 +516,11 @@ export const spec = { | |
} | ||
|
||
const bidFpd = { | ||
user: bidRequest.params.visitor || {}, | ||
context: bidRequest.params.inventory || {} | ||
user: {...bidRequest.params.visitor} || {}, | ||
context: {...bidRequest.params.inventory} || {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
}; | ||
|
||
if (bidRequest.params.keywords) bidFpd.context.keywords = bidRequest.params.keywords; | ||
if (bidRequest.params.keywords) bidFpd.context.keywords = (utils.isArray(bidRequest.params.keywords)) ? bidRequest.params.keywords.join(',') : bidRequest.params.keywords; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the plan was to not support the string or non array case in bidParams.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was but then I reviewed the existing tests and one test explicitly states that it should not error if set as a string. I dont like it but will assume there is a reason for the test that could break things in production. So for the time being I made sure this allows for both |
||
|
||
applyFPD(utils.mergeDeep({}, config.getConfig('fpd') || {}, bidRequest.fpd || {}, bidFpd), BANNER, data); | ||
|
||
|
@@ -885,21 +885,22 @@ function addVideoParameters(data, bidRequest) { | |
function applyFPD(fpd, mediaType, data) { | ||
const map = {user: {banner: 'tg_v.', code: 'user'}, context: {banner: 'tg_i.', code: 'site'}, adserver: 'dfp_ad_unit_code'}; | ||
let obj = {}; | ||
let impData = {}; | ||
let keywords = []; | ||
const validate = function(e, t) { | ||
if (typeof e === 'object' && !Array.isArray(e)) { | ||
utils.logWarn('Rubicon: Filtered FPD key: ', t, ': Expected value to be string, integer, or an array of strings/ints'); | ||
} else if (e) { | ||
return (Array.isArray(e)) ? e.filter(value => { | ||
if (typeof value !== 'object' && value) return value; | ||
|
||
utils.logWarn('Rubicon: Filtered value: ', value, 'for key', t, ': Expected value to be string, integer, or an array of strings/ints'); | ||
}).toString() : e.toString(); | ||
const validate = function(prop, key) { | ||
if (typeof prop === 'object' && !Array.isArray(prop)) { | ||
utils.logWarn('Rubicon: Filtered FPD key: ', key, ': Expected value to be string, integer, or an array of strings/ints'); | ||
} else if (utils.isNumber(prop) || prop) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a simple
would be a little more efficient. Most of the time the prop will not be falsey, so we should check that first regardless. And we know it will only hit the other side of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is outdated as well |
||
return (Array.isArray(prop)) ? prop.filter(value => { | ||
if (typeof value !== 'object' && (utils.isNumber(value) || value)) return value.toString(); | ||
|
||
utils.logWarn('Rubicon: Filtered value: ', value, 'for key', key, ': Expected value to be string, integer, or an array of strings/ints'); | ||
}).toString() : prop.toString(); | ||
} | ||
}; | ||
|
||
Object.keys(fpd).filter(value => fpd[value] && map[value] && typeof fpd[value] === 'object').forEach((type) => { | ||
obj[map[type].code] = Object.keys(fpd[type]).filter(value => fpd[type][value]).reduce((result, key) => { | ||
obj[map[type].code] = Object.keys(fpd[type]).filter(value => utils.isNumber(fpd[type][value]) || fpd[type][value]).reduce((result, key) => { | ||
if (key === 'keywords') { | ||
if (!Array.isArray(fpd[type][key]) && mediaType === BANNER) fpd[type][key] = [fpd[type][key]] | ||
|
||
|
@@ -911,9 +912,8 @@ function applyFPD(fpd, mediaType, data) { | |
} else if (key === 'adServer' || key === 'pbAdSlot') { | ||
(key === 'adServer') ? ['name', 'adSlot'].forEach(name => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These go inside of the imp array. Not at top level of the request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to imp[0] |
||
const value = validate(fpd[type][key][name]); | ||
|
||
if (value) utils.mergeDeep(result, {ext: {data: {adserver: {[name.toLowerCase()]: value.replace(/^\/+/, '')}}}}); | ||
}) : utils.mergeDeep(result, {ext: {data: {[key.toLowerCase()]: fpd[type][key].replace(/^\/+/, '')}}}); | ||
if (value) utils.deepSetValue(impData, `adserver.${name.toLowerCase()}`, value.replace(/^\/+/, '')) | ||
}) : impData[key.toLowerCase()] = fpd[type][key].replace(/^\/+/, '') | ||
} else { | ||
utils.mergeDeep(result, {ext: {data: {[key]: fpd[type][key]}}}); | ||
} | ||
|
@@ -923,6 +923,7 @@ function applyFPD(fpd, mediaType, data) { | |
|
||
if (mediaType === BANNER) { | ||
let duplicate = (typeof obj[map[type].code].ext === 'object' && obj[map[type].code].ext.data) || {}; | ||
|
||
Object.keys(duplicate).forEach((key) => { | ||
const val = (key === 'adserver') ? duplicate.adserver.adslot : validate(duplicate[key], key); | ||
|
||
|
@@ -931,6 +932,14 @@ function applyFPD(fpd, mediaType, data) { | |
} | ||
}); | ||
|
||
Object.keys(impData).forEach((key) => { | ||
if (mediaType === BANNER) { | ||
(map[key]) ? data[`tg_i.${map[key]}`] = impData[key].adslot : data[`tg_i.${key.toLowerCase()}`] = impData[key]; | ||
} else { | ||
utils.mergeDeep(data.imp[0], {ext: {context: {data: {[key]: impData[key]}}}}); | ||
} | ||
}); | ||
|
||
if (mediaType === BANNER) { | ||
let kw = validate(keywords, 'keywords'); | ||
if (kw) data.kw = kw; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this will work as expected.
Why did you change it from the previous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just leave it as:
And it will do what is intended (default to {})
The || {} never will get executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I removed this already no? I pushed twice this morning