Skip to content

Commit

Permalink
OpenX Bid Adapter: read segtax
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 committed Jul 26, 2021
1 parent 8a52fb1 commit e10a89a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
11 changes: 9 additions & 2 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,22 @@ function buildCommonQueryParamsFromBids(bids, bidderRequest) {

const firstPartyData = config.getConfig('ortb2.user.data')
if (Array.isArray(firstPartyData) && firstPartyData.length > 0) {
const sm = firstPartyData
// extract and merge valid segments by provider/taxonomy
const fpd = firstPartyData
.filter(
data => (Array.isArray(data.segment) &&
data.segment.length > 0 &&
data.name !== undefined &&
data.name.length > 0)
)
.reduce((acc, data) => {
const name = typeof data.ext === 'object' && data.ext.segtax ? `${data.name}/${data.ext.segtax}` : data.name;
acc[name] = (acc[name] || []).concat(data.segment.map(seg => seg.id));
return acc;
}, {})
const sm = Object.entries(fpd)
.map(
data => data.name + ':' + data.segment.map(seg => seg.id).join('|')
([name, segs], _) => name + ':' + segs.join('|')
)
.join(',')
if (sm.length > 0) {
Expand Down
20 changes: 17 additions & 3 deletions test/spec/modules/openxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1534,18 +1534,32 @@ describe('OpenxAdapter', function () {
describe('with segments', function () {
const TESTS = [
{
name: 'should send out the provider/segment data from first party config',
name: 'should send proprietary segment data from first party config',
config: {
ortb2: {
user: {
data: [
{name: 'dmp1', segment: [{id: 'foo'}, {id: 'bar'}]},
{name: 'dmp1', ext: {segtax: 4}, segment: [{id: 'foo'}, {id: 'bar'}]},
{name: 'dmp2', segment: [{id: 'baz'}]},
]
}
}
},
expect: 'dmp1:foo|bar,dmp2:baz',
expect: 'dmp1/4:foo|bar,dmp2:baz',
},
{
name: 'should combine same provider segment data from first party config',
config: {
ortb2: {
user: {
data: [
{name: 'dmp1', ext: {segtax: 4}, segment: [{id: 'foo'}, {id: 'bar'}]},
{name: 'dmp1', ext: {}, segment: [{id: 'baz'}]},
]
}
}
},
expect: 'dmp1/4:foo|bar,dmp1:baz',
},
{
name: 'should not send any segment data if first party config is incomplete',
Expand Down

0 comments on commit e10a89a

Please sign in to comment.