Skip to content

Commit

Permalink
Merge pull request #5 from voxmedia/ac-add-uid2
Browse files Browse the repository at this point in the history
[RPO-2922] - Add Prebid Unified Token
  • Loading branch information
antoinfive committed Oct 17, 2022
2 parents bcc6cd5 + a0bfc6b commit d4392ca
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/concertBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const spec = {
buildRequests: function(validBidRequests, bidderRequest) {
logMessage(validBidRequests);
logMessage(bidderRequest);

const eids = [];

let payload = {
meta: {
prebidVersion: '$prebid.version$',
Expand All @@ -49,6 +52,8 @@ export const spec = {
};

payload.slots = validBidRequests.map(bidRequest => {
collectEid(eids, bidRequest);

let slot = {
name: bidRequest.adUnitCode,
bidId: bidRequest.bidId,
Expand All @@ -65,6 +70,8 @@ export const spec = {
return slot;
});

payload.meta.eids = eids.filter(Boolean);

logMessage(payload);

return {
Expand Down Expand Up @@ -216,3 +223,25 @@ function consentAllowsPpid(bidderRequest) {

return (uspConsent || gdprConsent);
}

function collectEid(eids, bid) {
if (bid.userId) {
const eid = getUserId(bid.userId.uid2 && bid.userId.uid2.id, 'uidapi.com', undefined, 3)
eids.push(eid)
}
}

function getUserId(id, source, uidExt, atype) {
if (id) {
const uid = { id, atype };

if (uidExt) {
uid.ext = uidExt;
}

return {
source,
uids: [ uid ]
};
}
}
21 changes: 21 additions & 0 deletions test/spec/modules/concertBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ describe('ConcertAdapter', function () {

expect(payload.meta.uid).to.equal('foo');
});

it('should add uid2 to eids list if available', function() {
bidRequests[0].userId = { uid2: { id: 'uid123' } }

const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);
const meta = payload.meta

expect(meta.eids.length).to.equal(1);
expect(meta.eids[0].uids[0].id).to.equal('uid123')
expect(meta.eids[0].uids[0].atype).to.equal(3)
})

it('should return empty eids list if none are available', function() {
bidRequests[0].userId = { testId: { id: 'uid123' } }
const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);
const meta = payload.meta

expect(meta.eids.length).to.equal(0);
})
});

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

0 comments on commit d4392ca

Please sign in to comment.