Skip to content

Commit 75edabe

Browse files
pm-harshad-manePedro López Jiménez
authored and
Pedro López Jiménez
committed
PubMatic adapter to support TTD (prebid#3311)
* first commit * added unit test cases for TTD id
1 parent 44e4b5f commit 75edabe

File tree

2 files changed

+252
-0
lines changed

2 files changed

+252
-0
lines changed

modules/pubmaticBidAdapter.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,28 @@ function _handleDigitrustId(eids) {
346346
}
347347
}
348348

349+
function _handleTTDId(eids) {
350+
let adsrvrOrgId = config.getConfig('adsrvrOrgId');
351+
if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) {
352+
eids.push({
353+
'source': 'adserver.org',
354+
'uids': [
355+
{
356+
'id': adsrvrOrgId.TDID,
357+
'atype': 1,
358+
'ext': {
359+
'rtiPartner': 'TDID'
360+
}
361+
}
362+
]
363+
});
364+
}
365+
}
366+
349367
function _handleEids(payload) {
350368
let eids = [];
351369
_handleDigitrustId(eids);
370+
_handleTTDId(eids);
352371
if (eids.length > 0) {
353372
payload.user.eids = eids;
354373
}

test/spec/modules/pubmaticBidAdapter_spec.js

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,239 @@ describe('PubMatic adapter', function () {
640640
});
641641
});
642642

643+
describe('AdsrvrOrgId from config', function() {
644+
let sandbox;
645+
beforeEach(() => {
646+
sandbox = sinon.sandbox.create();
647+
});
648+
649+
afterEach(() => {
650+
sandbox.restore();
651+
});
652+
653+
it('Request should have adsrvrOrgId config params', function() {
654+
sandbox.stub(config, 'getConfig').callsFake((key) => {
655+
var config = {
656+
adsrvrOrgId: {
657+
'TDID': '5e740345-c25e-436d-b466-5f2f9fa95c17',
658+
'TDID_LOOKUP': 'TRUE',
659+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
660+
}
661+
};
662+
return config[key];
663+
});
664+
665+
let request = spec.buildRequests(bidRequests, {});
666+
let data = JSON.parse(request.data);
667+
expect(data.user.eids).to.deep.equal([{
668+
'source': 'adserver.org',
669+
'uids': [{
670+
'id': '5e740345-c25e-436d-b466-5f2f9fa95c17',
671+
'atype': 1,
672+
'ext': {
673+
'rtiPartner': 'TDID'
674+
}
675+
}]
676+
}]);
677+
});
678+
679+
it('Request should NOT have adsrvrOrgId config params if id in adsrvrOrgId is NOT string', function() {
680+
sandbox.stub(config, 'getConfig').callsFake((key) => {
681+
var config = {
682+
adsrvrOrgId: {
683+
'TDID': 1,
684+
'TDID_LOOKUP': 'TRUE',
685+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
686+
}
687+
};
688+
return config[key];
689+
});
690+
691+
let request = spec.buildRequests(bidRequests, {});
692+
let data = JSON.parse(request.data);
693+
expect(data.user.eids).to.deep.equal(undefined);
694+
});
695+
696+
it('Request should NOT have adsrvrOrgId config params if adsrvrOrgId is NOT object', function() {
697+
sandbox.stub(config, 'getConfig').callsFake((key) => {
698+
var config = {
699+
adsrvrOrgId: null
700+
};
701+
return config[key];
702+
});
703+
704+
let request = spec.buildRequests(bidRequests, {});
705+
let data = JSON.parse(request.data);
706+
expect(data.user.eids).to.deep.equal(undefined);
707+
});
708+
709+
it('Request should NOT have adsrvrOrgId config params if id in adsrvrOrgId is NOT set', function() {
710+
sandbox.stub(config, 'getConfig').callsFake((key) => {
711+
var config = {
712+
adsrvrOrgId: {
713+
'TDID_LOOKUP': 'TRUE',
714+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
715+
}
716+
};
717+
return config[key];
718+
});
719+
720+
let request = spec.buildRequests(bidRequests, {});
721+
let data = JSON.parse(request.data);
722+
expect(data.user.eids).to.deep.equal(undefined);
723+
});
724+
});
725+
726+
describe('AdsrvrOrgId and Digitrust', function() {
727+
// here we are considering cases only of accepting DigiTrustId from config
728+
let sandbox;
729+
beforeEach(() => {
730+
sandbox = sinon.sandbox.create();
731+
window.DigiTrust = {
732+
getUser: sandbox.spy()
733+
};
734+
});
735+
736+
afterEach(() => {
737+
sandbox.restore();
738+
delete window.DigiTrust;
739+
});
740+
741+
it('Request should have id of both AdsrvrOrgId and Digitrust if both have returned valid ids', function() {
742+
sandbox.stub(config, 'getConfig').callsFake((key) => {
743+
var config = {
744+
adsrvrOrgId: {
745+
'TDID': '5e740345-c25e-436d-b466-5f2f9fa95c17',
746+
'TDID_LOOKUP': 'TRUE',
747+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
748+
},
749+
digiTrustId: {
750+
success: true,
751+
identity: {
752+
privacy: {optout: false},
753+
id: 'testId',
754+
keyv: 4
755+
}
756+
}
757+
};
758+
return config[key];
759+
});
760+
761+
let request = spec.buildRequests(bidRequests, {});
762+
let data = JSON.parse(request.data);
763+
expect(data.user.eids).to.deep.equal([{
764+
'source': 'digitru.st',
765+
'uids': [{
766+
'id': 'testId',
767+
'atype': 1,
768+
'ext': {
769+
'keyv': 4
770+
}
771+
}]
772+
}, {
773+
'source': 'adserver.org',
774+
'uids': [{
775+
'id': '5e740345-c25e-436d-b466-5f2f9fa95c17',
776+
'atype': 1,
777+
'ext': {
778+
'rtiPartner': 'TDID'
779+
}
780+
}]
781+
}]);
782+
});
783+
784+
it('Request should have id of only AdsrvrOrgId and NOT Digitrust if only AdsrvrOrgId have returned valid id', function() {
785+
sandbox.stub(config, 'getConfig').callsFake((key) => {
786+
var config = {
787+
adsrvrOrgId: {
788+
'TDID': '5e740345-c25e-436d-b466-5f2f9fa95c17',
789+
'TDID_LOOKUP': 'TRUE',
790+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
791+
},
792+
digiTrustId: {
793+
success: true,
794+
identity: {
795+
privacy: {optout: true},
796+
id: 'testId',
797+
keyv: 4
798+
}
799+
}
800+
};
801+
return config[key];
802+
});
803+
804+
let request = spec.buildRequests(bidRequests, {});
805+
let data = JSON.parse(request.data);
806+
expect(data.user.eids).to.deep.equal([{
807+
'source': 'adserver.org',
808+
'uids': [{
809+
'id': '5e740345-c25e-436d-b466-5f2f9fa95c17',
810+
'atype': 1,
811+
'ext': {
812+
'rtiPartner': 'TDID'
813+
}
814+
}]
815+
}]);
816+
});
817+
818+
it('Request should have id of only Digitrust and NOT AdsrvrOrgId if only Digitrust have returned valid id', function() {
819+
sandbox.stub(config, 'getConfig').callsFake((key) => {
820+
var config = {
821+
adsrvrOrgId: {
822+
'TDID_LOOKUP': 'TRUE',
823+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
824+
},
825+
digiTrustId: {
826+
success: true,
827+
identity: {
828+
privacy: {optout: false},
829+
id: 'testId',
830+
keyv: 4
831+
}
832+
}
833+
};
834+
return config[key];
835+
});
836+
837+
let request = spec.buildRequests(bidRequests, {});
838+
let data = JSON.parse(request.data);
839+
expect(data.user.eids).to.deep.equal([{
840+
'source': 'digitru.st',
841+
'uids': [{
842+
'id': 'testId',
843+
'atype': 1,
844+
'ext': {
845+
'keyv': 4
846+
}
847+
}]
848+
}]);
849+
});
850+
851+
it('Request should NOT have id of Digitrust and NOT AdsrvrOrgId if only both have NOT returned valid ids', function() {
852+
sandbox.stub(config, 'getConfig').callsFake((key) => {
853+
var config = {
854+
adsrvrOrgId: {
855+
'TDID_LOOKUP': 'TRUE',
856+
'TDID_CREATED_AT': '2018-10-01T07:05:40'
857+
},
858+
digiTrustId: {
859+
success: true,
860+
identity: {
861+
privacy: {optout: true},
862+
id: 'testId',
863+
keyv: 4
864+
}
865+
}
866+
};
867+
return config[key];
868+
});
869+
870+
let request = spec.buildRequests(bidRequests, {});
871+
let data = JSON.parse(request.data);
872+
expect(data.user.eids).to.deep.equal(undefined);
873+
});
874+
});
875+
643876
it('Request params check for video ad', function () {
644877
let request = spec.buildRequests(videoBidRequests);
645878
let data = JSON.parse(request.data);

0 commit comments

Comments
 (0)