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

Sonobi Bid Adapter: send eids in bid request. #6364

Merged
merged 6 commits into from
Mar 11, 2021
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
16 changes: 13 additions & 3 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage } from '../src/utils.js';
import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage, deepClone } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import { userSync } from '../src/userSync.js';

const BIDDER_CODE = 'sonobi';
const STR_ENDPOINT = 'https://apex.go.sonobi.com/trinity.json';
const PAGEVIEW_ID = generateUUID();
Expand Down Expand Up @@ -117,7 +116,18 @@ export const spec = {
payload.schain = JSON.stringify(validBidRequests[0].schain)
}
if (deepAccess(validBidRequests[0], 'userId') && Object.keys(validBidRequests[0].userId).length > 0) {
payload.userid = JSON.stringify(validBidRequests[0].userId);
const userIds = deepClone(validBidRequests[0].userId);

if (userIds.id5id) {
userIds.id5id = deepAccess(userIds, 'id5id.uid');
aleksatr marked this conversation as resolved.
Show resolved Hide resolved
}

payload.userid = JSON.stringify(userIds);
}

const eids = deepAccess(validBidRequests[0], 'userIdAsEids');
if (Array.isArray(eids) && eids.length > 0) {
payload.eids = JSON.stringify(eids);
}

let keywords = validBidRequests[0].params.keywords; // a CSV of keywords
Expand Down
85 changes: 81 additions & 4 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,92 @@ describe('SonobiBidAdapter', function () {
expect(JSON.parse(bidRequests.data.schain)).to.deep.equal(bidRequest[0].schain)
});

it('should return a properly formatted request with eids as a JSON-encoded set of eids', function () {
bidRequest[0].userIdAsEids = [
{
'source': 'pubcid.org',
'uids': [
{
'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a',
'atype': 1
}
]
},
{
'source': 'sharedid.org',
'uids': [
{
'id': '01ERJ6W40EXJZNQJVJZWASEG7J',
'atype': 1,
'ext': {
'third': '01ERJ6W40EXJZNQJVJZWASEG7J'
}
}
]
}
];
bidRequest[1].userIdAsEids = [
{
'source': 'pubcid.org',
'uids': [
{
'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a',
'atype': 1
}
]
},
{
'source': 'sharedid.org',
'uids': [
{
'id': '01ERJ6W40EXJZNQJVJZWASEG7J',
'atype': 1,
'ext': {
'third': '01ERJ6W40EXJZNQJVJZWASEG7J'
}
}
]
}
];
const bidRequests = spec.buildRequests(bidRequest, bidderRequests);
expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json');
expect(bidRequests.method).to.equal('GET');
expect(bidRequests.data.ref).not.to.be.empty;
expect(bidRequests.data.s).not.to.be.empty;
expect(JSON.parse(bidRequests.data.eids)).to.eql([
{
'source': 'pubcid.org',
'uids': [
{
'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a',
'atype': 1
}
]
},
{
'source': 'sharedid.org',
'uids': [
{
'id': '01ERJ6W40EXJZNQJVJZWASEG7J',
'atype': 1,
'ext': {
'third': '01ERJ6W40EXJZNQJVJZWASEG7J'
}
}
]
}
]);
});

it('should return a properly formatted request with userid as a JSON-encoded set of User ID results', function () {
bidRequest[0].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101'};
bidRequest[1].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101'};
bidRequest[0].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': {'uid': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ', 'ext': {'linkType': 2}}};
bidRequest[1].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': {'uid': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ', 'ext': {'linkType': 2}}};
const bidRequests = spec.buildRequests(bidRequest, bidderRequests);
expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json');
expect(bidRequests.method).to.equal('GET');
expect(bidRequests.data.ref).not.to.be.empty;
expect(bidRequests.data.s).not.to.be.empty;
expect(JSON.parse(bidRequests.data.userid)).to.eql({'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101'});
expect(JSON.parse(bidRequests.data.userid)).to.eql({'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ'});
});

it('should return a properly formatted request with userid omitted if there are no userIds', function () {
Expand Down Expand Up @@ -469,7 +546,7 @@ describe('SonobiBidAdapter', function () {
];
const bidRequests = spec.buildRequests(bRequest, bidderRequests);
expect(bidRequests.url).to.equal('https://iad-2-apex.go.sonobi.com/trinity.json');
})
});
});

describe('.interpretResponse', function () {
Expand Down