Skip to content

Commit 918ffb9

Browse files
Adding new user ids to Teads adapter (#8951)
1 parent 921d441 commit 918ffb9

File tree

2 files changed

+97
-21
lines changed

2 files changed

+97
-21
lines changed

modules/teadsBidAdapter.js

+32-10
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const spec = {
5454
data: bids,
5555
deviceWidth: screen.width,
5656
hb_version: '$prebid.version$',
57-
...getUnifiedId2Parameter(deepAccess(validBidRequests, '0.userId.uid2')),
57+
...getSharedViewerIdParameters(validBidRequests),
5858
...getFirstPartyTeadsIdParameter()
5959
};
6060

@@ -124,6 +124,37 @@ export const spec = {
124124
}
125125
};
126126

127+
/**
128+
*
129+
* @param validBidRequests an array of bids
130+
* @returns {{sharedViewerIdKey : 'sharedViewerIdValue'}} object with all sharedviewerids
131+
*/
132+
function getSharedViewerIdParameters(validBidRequests) {
133+
const sharedViewerIdMapping = {
134+
unifiedId2: 'uid2.id', // uid2IdSystem
135+
liveRampId: 'idl_env', // identityLinkIdSystem
136+
lotamePanoramaId: 'lotamePanoramaId', // lotamePanoramaIdSystem
137+
id5Id: 'id5id.uid', // id5IdSystem
138+
criteoId: 'criteoId', // criteoIdSystem
139+
yahooConnectId: 'connectId', // connectIdSystem
140+
quantcastId: 'quantcastId', // quantcastIdSystem
141+
epsilonPublisherLinkId: 'publinkId', // publinkIdSystem
142+
publisherFirstPartyViewerId: 'pubcid', // sharedIdSystem
143+
merkleId: 'merkleId.id', // merkleIdSystem
144+
kinessoId: 'kpuid' // kinessoIdSystem
145+
}
146+
147+
let sharedViewerIdObject = {};
148+
for (const sharedViewerId in sharedViewerIdMapping) {
149+
const key = sharedViewerIdMapping[sharedViewerId];
150+
const value = deepAccess(validBidRequests, `0.userId.${key}`);
151+
if (value) {
152+
sharedViewerIdObject[sharedViewerId] = value;
153+
}
154+
}
155+
return sharedViewerIdObject;
156+
}
157+
127158
function getReferrerInfo(bidderRequest) {
128159
let ref = '';
129160
if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.page) {
@@ -228,15 +259,6 @@ function _validateId(id) {
228259
return (parseInt(id) > 0);
229260
}
230261

231-
/**
232-
* Get unified ID v2 parameter to be sent in bid request.
233-
* @param `{id: string} | undefined` optionalUid2 uid2 user ID object available if "uid2IdSystem" module is enabled.
234-
* @returns `{} | {unifiedId2: string}`
235-
*/
236-
function getUnifiedId2Parameter(optionalUid2) {
237-
return optionalUid2 ? { unifiedId2: optionalUid2.id } : {};
238-
}
239-
240262
/**
241263
* Get the first-party cookie Teads ID parameter to be sent in bid request.
242264
* @returns `{} | {firstPartyCookieTeadsId: string}`

test/spec/modules/teadsBidAdapter_spec.js

+65-11
Original file line numberDiff line numberDiff line change
@@ -470,35 +470,89 @@ describe('teadsBidAdapter', () => {
470470
'deviceWidth': 1680
471471
};
472472

473-
describe('Unified ID v2', function () {
474-
it('should not add unifiedId2 param to payload if uid2 system is not enabled', function () {
473+
const userIdModules = {
474+
unifiedId2: {uid2: {id: 'unifiedId2-id'}},
475+
liveRampId: {idl_env: 'liveRampId-id'},
476+
lotamePanoramaId: {lotamePanoramaId: 'lotamePanoramaId-id'},
477+
id5Id: {id5id: {uid: 'id5Id-id'}},
478+
criteoId: {criteoId: 'criteoId-id'},
479+
yahooConnectId: {connectId: 'yahooConnectId-id'},
480+
quantcastId: {quantcastId: 'quantcastId-id'},
481+
epsilonPublisherLinkId: {publinkId: 'epsilonPublisherLinkId-id'},
482+
publisherFirstPartyViewerId: {pubcid: 'publisherFirstPartyViewerId-id'},
483+
merkleId: {merkleId: {id: 'merkleId-id'}},
484+
kinessoId: {kpuid: 'kinessoId-id'}
485+
};
486+
487+
describe('User Id Modules', function () {
488+
it(`should not add param to payload if user id system is not enabled`, function () {
475489
const bidRequest = {
476490
...baseBidRequest,
477-
userId: {} // no "uid2" property -> assumption that the Unified ID v2 system is disabled
491+
userId: {} // no property -> assumption that the system is disabled
478492
};
479493

480494
const request = spec.buildRequests([bidRequest], bidderResquestDefault);
481495
const payload = JSON.parse(request.data);
482496

483-
expect(payload).not.to.have.property('unifiedId2');
497+
for (const userId in userIdModules) {
498+
expect(payload, userId).not.to.have.property(userId);
499+
}
500+
});
501+
502+
it(`should not add param to payload if user id field is absent`, function () {
503+
const request = spec.buildRequests([baseBidRequest], bidderResquestDefault);
504+
const payload = JSON.parse(request.data);
505+
506+
for (const userId in userIdModules) {
507+
expect(payload, userId).not.to.have.property(userId);
508+
}
484509
});
485510

486-
it('should add unifiedId2 param to payload if uid2 system is enabled', function () {
511+
it(`should not add param to payload if user id is enabled but there is no value`, function () {
487512
const bidRequest = {
488513
...baseBidRequest,
489514
userId: {
490-
uid2: {
491-
id: 'my-unified-id-2'
492-
}
515+
idl_env: '',
516+
pubcid: 'publisherFirstPartyViewerId-id'
493517
}
494518
};
495519

496520
const request = spec.buildRequests([bidRequest], bidderResquestDefault);
497521
const payload = JSON.parse(request.data);
498522

499-
expect(payload.unifiedId2).to.equal('my-unified-id-2');
500-
})
501-
});
523+
expect(payload).not.to.have.property('liveRampId');
524+
expect(payload['publisherFirstPartyViewerId']).to.equal('publisherFirstPartyViewerId-id');
525+
});
526+
527+
it(`should add userId param to payload for each enabled user id system`, function () {
528+
let userIdObject = {};
529+
for (const userId in userIdModules) {
530+
userIdObject = {
531+
...userIdObject,
532+
...userIdModules[userId]
533+
}
534+
}
535+
const bidRequest = {
536+
...baseBidRequest,
537+
userId: userIdObject
538+
};
539+
540+
const request = spec.buildRequests([bidRequest], bidderResquestDefault);
541+
const payload = JSON.parse(request.data);
542+
543+
expect(payload['unifiedId2']).to.equal('unifiedId2-id');
544+
expect(payload['liveRampId']).to.equal('liveRampId-id');
545+
expect(payload['lotamePanoramaId']).to.equal('lotamePanoramaId-id');
546+
expect(payload['id5Id']).to.equal('id5Id-id');
547+
expect(payload['criteoId']).to.equal('criteoId-id');
548+
expect(payload['yahooConnectId']).to.equal('yahooConnectId-id');
549+
expect(payload['quantcastId']).to.equal('quantcastId-id');
550+
expect(payload['epsilonPublisherLinkId']).to.equal('epsilonPublisherLinkId-id');
551+
expect(payload['publisherFirstPartyViewerId']).to.equal('publisherFirstPartyViewerId-id');
552+
expect(payload['merkleId']).to.equal('merkleId-id');
553+
expect(payload['kinessoId']).to.equal('kinessoId-id');
554+
});
555+
})
502556

503557
describe('First-party cookie Teads ID', function () {
504558
it('should not add firstPartyCookieTeadsId param to payload if cookies are not enabled', function () {

0 commit comments

Comments
 (0)