Skip to content

Commit 0446d10

Browse files
pm-harshad-maneAlex
authored and
Alex
committed
PubMatic adapter support to read TTD Id from UserId module (prebid#3834)
* in-dev * added unit test cases * adding isStr check on userId.tdid * review suggestion
1 parent 0172ac7 commit 0446d10

File tree

2 files changed

+83
-6
lines changed

2 files changed

+83
-6
lines changed

modules/pubmaticBidAdapter.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,20 @@ function _handleDigitrustId(eids) {
601601
}
602602
}
603603

604-
function _handleTTDId(eids) {
604+
function _handleTTDId(eids, validBidRequests) {
605+
let ttdId = null;
605606
let adsrvrOrgId = config.getConfig('adsrvrOrgId');
606-
if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) {
607+
if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.tdid'))) {
608+
ttdId = validBidRequests[0].userId.tdid;
609+
} else if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) {
610+
ttdId = adsrvrOrgId.TDID;
611+
}
612+
613+
if (ttdId !== null) {
607614
eids.push({
608615
'source': 'adserver.org',
609616
'uids': [{
610-
'id': adsrvrOrgId.TDID,
617+
'id': ttdId,
611618
'atype': 1,
612619
'ext': {
613620
'rtiPartner': 'TDID'
@@ -617,10 +624,10 @@ function _handleTTDId(eids) {
617624
}
618625
}
619626

620-
function _handleEids(payload) {
627+
function _handleEids(payload, validBidRequests) {
621628
let eids = [];
622629
_handleDigitrustId(eids);
623-
_handleTTDId(eids);
630+
_handleTTDId(eids, validBidRequests);
624631
if (eids.length > 0) {
625632
payload.user.eids = eids;
626633
}
@@ -877,7 +884,7 @@ export const spec = {
877884
}
878885
}
879886

880-
_handleEids(payload);
887+
_handleEids(payload, validBidRequests);
881888
_blockedIabCategoriesValidation(payload, blockedIabCategories);
882889
return {
883890
method: 'POST',

test/spec/modules/pubmaticBidAdapter_spec.js

+70
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,76 @@ describe('PubMatic adapter', function () {
12351235
});
12361236
});
12371237

1238+
describe('AdsrvrOrgId from userId module', function() {
1239+
let sandbox;
1240+
beforeEach(() => {
1241+
sandbox = sinon.sandbox.create();
1242+
});
1243+
1244+
afterEach(() => {
1245+
sandbox.restore();
1246+
});
1247+
1248+
it('Request should have AdsrvrOrgId config params', function() {
1249+
bidRequests[0].userId = {};
1250+
bidRequests[0].userId.tdid = 'TTD_ID_FROM_USER_ID_MODULE';
1251+
let request = spec.buildRequests(bidRequests, {});
1252+
let data = JSON.parse(request.data);
1253+
expect(data.user.eids).to.deep.equal([{
1254+
'source': 'adserver.org',
1255+
'uids': [{
1256+
'id': 'TTD_ID_FROM_USER_ID_MODULE',
1257+
'atype': 1,
1258+
'ext': {
1259+
'rtiPartner': 'TDID'
1260+
}
1261+
}]
1262+
}]);
1263+
});
1264+
1265+
it('Request should have adsrvrOrgId from UserId Module if config and userId module both have TTD ID', function() {
1266+
sandbox.stub(config, 'getConfig').callsFake((key) => {
1267+
var config = {
1268+
adsrvrOrgId: {
1269+
'TDID': 'TTD_ID_FROM_CONFIG',
1270+
'TDID_LOOKUP': 'TRUE',
1271+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
1272+
}
1273+
};
1274+
return config[key];
1275+
});
1276+
bidRequests[0].userId = {};
1277+
bidRequests[0].userId.tdid = 'TTD_ID_FROM_USER_ID_MODULE';
1278+
let request = spec.buildRequests(bidRequests, {});
1279+
let data = JSON.parse(request.data);
1280+
expect(data.user.eids).to.deep.equal([{
1281+
'source': 'adserver.org',
1282+
'uids': [{
1283+
'id': 'TTD_ID_FROM_USER_ID_MODULE',
1284+
'atype': 1,
1285+
'ext': {
1286+
'rtiPartner': 'TDID'
1287+
}
1288+
}]
1289+
}]);
1290+
});
1291+
1292+
it('Request should NOT have adsrvrOrgId params if userId is NOT object', function() {
1293+
let request = spec.buildRequests(bidRequests, {});
1294+
let data = JSON.parse(request.data);
1295+
expect(data.user.eids).to.deep.equal(undefined);
1296+
});
1297+
1298+
it('Request should NOT have adsrvrOrgId params if userId.tdid is NOT string', function() {
1299+
bidRequests[0].userId = {
1300+
tdid: 1234
1301+
};
1302+
let request = spec.buildRequests(bidRequests, {});
1303+
let data = JSON.parse(request.data);
1304+
expect(data.user.eids).to.deep.equal(undefined);
1305+
});
1306+
});
1307+
12381308
describe('AdsrvrOrgId and Digitrust', function() {
12391309
// here we are considering cases only of accepting DigiTrustId from config
12401310
let sandbox;

0 commit comments

Comments
 (0)