Skip to content

Commit

Permalink
optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Dec 12, 2024
1 parent 2c6d762 commit a37be5a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 34 deletions.
14 changes: 8 additions & 6 deletions modules/prebidServerBidAdapter/bidderConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export function extractEids({global, bidder}) {
entries.push(entry);
}
if (bySource[eid.source] == null) {
bySource[eid.source] = eid;
} else if (!conflicts.has(eid.source) && !deepEqual(bySource[eid.source], eid)) {
bySource[eid.source] = entry.eid;
} else if (entry.eid === eid) {
// if this is the first time we see this eid, but not the first time we see its source, we have a conflict
conflicts.add(eid.source);
}
return entry;
Expand Down Expand Up @@ -138,19 +139,20 @@ function replaceEids({global, bidder}) {
}
Object.entries(consolidated.bidder).forEach(([bidderCode, bidderEids]) => {
if (bidderEids.length) {
deepSetValue(bidder[bidderCode], 'user.ext.eids', consolidated.global.concat(bidderEids));
deepSetValue(bidder[bidderCode], 'user.ext.eids', bidderEids);
}
})
return {global, bidder}
}

export function premergeFpd(ortb2Fragments) {
if (ortb2Fragments == null || ortb2Fragments.bidder == null) {
if (ortb2Fragments == null || Object.keys(ortb2Fragments.bidder || {}).length === 0) {
return ortb2Fragments;
} else {
return replaceEids({
ortb2Fragments = replaceEids(ortb2Fragments);
return {
...ortb2Fragments,
bidder: getPBSBidderConfig(ortb2Fragments)
})
};
}
}
110 changes: 82 additions & 28 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2070,41 +2070,95 @@ describe('S2S Adapter', function () {
});
});

it('should pass user.ext.eids from FPD', function () {
config.setConfig({s2sConfig: CONFIG});
const req = {
...REQUEST,
ortb2Fragments: {
global: {
user: {
ext: {
eids: [{source: '1', id: 1}, {source: '2', id: 2}]
}
}
},
bidder: {
appnexus: {
describe('user.ext.eids', () => {
let req;
beforeEach(() => {
const s2sConfig = {
...CONFIG,
bidders: ['appnexus', 'rubicon']
}
config.setConfig({s2sConfig});
req = {
...REQUEST,
s2sConfig,
ortb2Fragments: {
global: {
user: {
ext: {
eids: [{source: '3', id: 3}]
eids: [{source: 'idA', id: 1}, {source: 'idB', id: 2}]
}
}
},
bidder: {
appnexus: {
user: {
ext: {
eids: [{source: 'idC', id: 3}]
}
}
}
}
}
}
}
adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax);
const payload = JSON.parse(server.requests[0].requestBody);
expect(payload.user.ext.eids).to.eql([
{source: '1', id: 1},
{source: '2', id: 2},
{source: '3', id: 3}
]);
expect(payload.ext.prebid.data.eidpermissions).to.eql([{
bidders: ['appnexus'],
source: '3'
}]);
});
})
it('should get picked up from from FPD', function () {
adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax);
const payload = JSON.parse(server.requests[0].requestBody);
expect(payload.user.ext.eids).to.eql([
{source: 'idA', id: 1},
{source: 'idB', id: 2},
{source: 'idC', id: 3}
]);
expect(payload.ext.prebid.data.eidpermissions).to.eql([{
bidders: ['appnexus'],
source: 'idC'
}]);
});

it('should repeat global EIDs when bidder-specific EIDs conflict', () => {
BID_REQUESTS.push({
...BID_REQUESTS[0],
bidderCode: 'rubicon',
bids: [{
bidder: 'rubicon',
params: {}
}]
})
req.ortb2Fragments.bidder.rubicon = {
user: {
ext: {
eids: [{source: 'idC', id: 4}]
}
}
}
adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax);
const payload = JSON.parse(server.requests[0].requestBody);
const globalEids = [
{source: 'idA', id: 1},
{source: 'idB', id: 2},
]
expect(payload.user.ext.eids).to.eql(globalEids);
expect(payload.ext.prebid?.data?.eidpermissions).to.not.exist;
expect(payload.ext.prebid.bidderconfig).to.have.deep.members([
{
bidders: ['appnexus'],
config: {
ortb2: {
user: {ext: {eids: globalEids.concat([{source: 'idC', id: 3}])}}
}
}
},
{
bidders: ['rubicon'],
config: {
ortb2: {
user: {ext: {eids: globalEids.concat([{source: 'idC', id: 4}])}}
}
}
}
])
})
})

it('when config \'currency.adServerCurrency\' value is a string: ORTB has property \'cur\' value set to a single item array', function () {
config.setConfig({
Expand Down

0 comments on commit a37be5a

Please sign in to comment.