Skip to content

Commit 2cf9331

Browse files
authored
DAS Bid Adapter: forward user.eids from ortb2 to OpenRTB request (#90)
* Feature/add user.eids handling from ortb2 in dasBidAdapter * Feature/update user.eids handling to use userIdAsEids in dasBidAdapter
1 parent 63f33b8 commit 2cf9331

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

modules/dasBidAdapter.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ function buildUserIds(customParams) {
164164
return userIds;
165165
}
166166

167+
function buildUserEids(bidRequests) {
168+
const eids = deepAccess(bidRequests, '0.userIdAsEids');
169+
if (!Array.isArray(eids) || eids.length === 0) {
170+
return null;
171+
}
172+
173+
const onetEids = eids.filter(eid => eid.source === 'onet.pl');
174+
175+
return onetEids.length > 0 ? onetEids : null;
176+
}
177+
167178
function getNpaFromPubConsent(pubConsent) {
168179
const params = new URLSearchParams(pubConsent);
169180
return params.get('npa') === '1';
@@ -259,6 +270,12 @@ function buildOpenRTBRequest(bidRequests, bidderRequest) {
259270
}
260271
}
261272

273+
const userEids = buildUserEids(bidRequests);
274+
275+
if (userEids) {
276+
request.user.eids = userEids;
277+
}
278+
262279
return request;
263280
}
264281

test/spec/modules/dasBidAdapter_spec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,5 +575,59 @@ describe('dasBidAdapter', function () {
575575
const bidResponses = spec.interpretResponse(nativeResponse);
576576
expect(bidResponses[0].native).to.deep.equal({});
577577
});
578+
579+
describe('user.eids from userIdAsEids', function () {
580+
const onetEid = {
581+
source: 'onet.pl',
582+
inserter: 'onet.pl',
583+
uids: [{ id: 'test-artemis-id', atype: 1, ext: { id_type: 'tracking', consent_required: true } }]
584+
};
585+
586+
it('should include user.eids when onet.pl EID is present in userIdAsEids', function () {
587+
const bidRequestsWithEids = [{
588+
...bidRequests[0],
589+
userIdAsEids: [onetEid]
590+
}];
591+
592+
const request = spec.buildRequests(bidRequestsWithEids, bidderRequest);
593+
const payload = JSON.parse(decodeURIComponent(new URL(request.url).searchParams.get('data')));
594+
595+
expect(payload.user.eids).to.be.an('array').with.lengthOf(1);
596+
expect(payload.user.eids[0].source).to.equal('onet.pl');
597+
expect(payload.user.eids[0].inserter).to.equal('onet.pl');
598+
expect(payload.user.eids[0].uids[0].id).to.equal('test-artemis-id');
599+
expect(payload.user.eids[0].uids[0].atype).to.equal(1);
600+
expect(payload.user.eids[0].uids[0].ext.id_type).to.equal('tracking');
601+
expect(payload.user.eids[0].uids[0].ext.consent_required).to.equal(true);
602+
});
603+
604+
it('should not include user.eids when userIdAsEids is absent', function () {
605+
const request = spec.buildRequests(bidRequests, bidderRequest);
606+
const payload = JSON.parse(decodeURIComponent(new URL(request.url).searchParams.get('data')));
607+
608+
expect(payload.user).to.not.have.property('eids');
609+
});
610+
611+
it('should not include user.eids when userIdAsEids contains no onet.pl source', function () {
612+
const bidRequestsWithOtherEid = [{
613+
...bidRequests[0],
614+
userIdAsEids: [{ source: 'other-source.com', uids: [{ id: 'some-id', atype: 1 }] }]
615+
}];
616+
617+
const request = spec.buildRequests(bidRequestsWithOtherEid, bidderRequest);
618+
const payload = JSON.parse(decodeURIComponent(new URL(request.url).searchParams.get('data')));
619+
620+
expect(payload.user).to.not.have.property('eids');
621+
});
622+
623+
it('should not include user.eids when userIdAsEids is empty', function () {
624+
const bidRequestsWithEmptyEids = [{ ...bidRequests[0], userIdAsEids: [] }];
625+
626+
const request = spec.buildRequests(bidRequestsWithEmptyEids, bidderRequest);
627+
const payload = JSON.parse(decodeURIComponent(new URL(request.url).searchParams.get('data')));
628+
629+
expect(payload.user).to.not.have.property('eids');
630+
});
631+
});
578632
});
579633
});

0 commit comments

Comments
 (0)