Skip to content

Commit d6e0269

Browse files
pm-harshad-manePedro López Jiménez
authored and
Pedro López Jiménez
committed
PubMatic to support DigiTrust Id passing (prebid#3160)
* in-dev changes * included config * Unit test cases for DigitrustId passing in PubMatic bid adapter * eslint fixes * removed a comment * replaced "() => {" with "() => {"
1 parent 0b9b428 commit d6e0269

File tree

2 files changed

+235
-0
lines changed

2 files changed

+235
-0
lines changed

modules/pubmaticBidAdapter.js

+43
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import * as utils from 'src/utils';
22
import { registerBidder } from 'src/adapters/bidderFactory';
33
import { BANNER, VIDEO } from 'src/mediaTypes';
4+
import {config} from 'src/config';
45
const constants = require('src/constants.json');
56

67
const BIDDER_CODE = 'pubmatic';
78
const ENDPOINT = '//hbopenbid.pubmatic.com/translator?source=prebid-client';
89
const USYNCURL = '//ads.pubmatic.com/AdServer/js/showad.js#PIX&kdntuid=1&p=';
910
const DEFAULT_CURRENCY = 'USD';
1011
const AUCTION_TYPE = 1;
12+
const PUBMATIC_DIGITRUST_KEY = 'nFIn8aLzbd';
1113
const UNDEFINED = undefined;
1214
const CUSTOM_PARAMS = {
1315
kadpageurl: '', // Custom page url
@@ -313,6 +315,45 @@ function _createImpressionObject(bid, conf) {
313315
return impObj;
314316
}
315317

318+
function _getDigiTrustObject(key) {
319+
function getDigiTrustId() {
320+
let digiTrustUser = window.DigiTrust && (config.getConfig('digiTrustId') || window.DigiTrust.getUser({member: key}));
321+
return (digiTrustUser && digiTrustUser.success && digiTrustUser.identity) || null;
322+
}
323+
let digiTrustId = getDigiTrustId();
324+
// Verify there is an ID and this user has not opted out
325+
if (!digiTrustId || (digiTrustId.privacy && digiTrustId.privacy.optout)) {
326+
return null;
327+
}
328+
return digiTrustId;
329+
}
330+
331+
function _handleDigitrustId(eids) {
332+
let digiTrustId = _getDigiTrustObject(PUBMATIC_DIGITRUST_KEY);
333+
if (digiTrustId !== null) {
334+
eids.push({
335+
'source': 'digitru.st',
336+
'uids': [
337+
{
338+
'id': digiTrustId.id || '',
339+
'atype': 1,
340+
'ext': {
341+
'keyv': parseInt(digiTrustId.keyv) || 0
342+
}
343+
}
344+
]
345+
});
346+
}
347+
}
348+
349+
function _handleEids(payload) {
350+
let eids = [];
351+
_handleDigitrustId(eids);
352+
if (eids.length > 0) {
353+
payload.user.eids = eids;
354+
}
355+
}
356+
316357
export const spec = {
317358
code: BIDDER_CODE,
318359
supportedMediaTypes: [BANNER, VIDEO],
@@ -503,6 +544,8 @@ export const spec = {
503544
);
504545
}
505546

547+
_handleEids(payload);
548+
506549
return {
507550
method: 'POST',
508551
url: ENDPOINT,

test/spec/modules/pubmaticBidAdapter_spec.js

+192
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {expect} from 'chai';
22
import {spec} from 'modules/pubmaticBidAdapter';
33
import * as utils from 'src/utils';
4+
import {config} from 'src/config';
45
const constants = require('src/constants.json');
56

67
describe('PubMatic adapter', function () {
@@ -448,6 +449,197 @@ describe('PubMatic adapter', function () {
448449
expect(data.imp[0].ext.pmZoneId).to.equal(bidRequests[0].params.pmzoneid.split(',').slice(0, 50).map(id => id.trim()).join()); // pmzoneid
449450
});
450451

452+
it('Request should have digitrust params', function() {
453+
window.DigiTrust = {
454+
getUser: function () {
455+
}
456+
};
457+
var bidRequest = {};
458+
let sandbox = sinon.sandbox.create();
459+
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
460+
({
461+
success: true,
462+
identity: {
463+
privacy: {optout: false},
464+
id: 'testId',
465+
keyv: 4
466+
}
467+
})
468+
);
469+
470+
let request = spec.buildRequests(bidRequests, bidRequest);
471+
let data = JSON.parse(request.data);
472+
expect(data.user.eids).to.deep.equal([{
473+
'source': 'digitru.st',
474+
'uids': [{
475+
'id': 'testId',
476+
'atype': 1,
477+
'ext': {
478+
'keyv': 4
479+
}
480+
}]
481+
}]);
482+
sandbox.restore();
483+
delete window.DigiTrust;
484+
});
485+
486+
it('Request should not have digitrust params when DigiTrust not loaded', function() {
487+
let request = spec.buildRequests(bidRequests, {});
488+
let data = JSON.parse(request.data);
489+
expect(data.user.eids).to.deep.equal(undefined);
490+
});
491+
492+
it('Request should not have digitrust params due to optout', function() {
493+
window.DigiTrust = {
494+
getUser: function () {
495+
}
496+
};
497+
let sandbox = sinon.sandbox.create();
498+
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
499+
({
500+
success: true,
501+
identity: {
502+
privacy: {optout: true},
503+
id: 'testId',
504+
keyv: 4
505+
}
506+
})
507+
);
508+
509+
let request = spec.buildRequests(bidRequests, {});
510+
let data = JSON.parse(request.data);
511+
expect(data.user.eids).to.deep.equal(undefined);
512+
sandbox.restore();
513+
delete window.DigiTrust;
514+
});
515+
516+
it('Request should not have digitrust params due to failure', function() {
517+
window.DigiTrust = {
518+
getUser: function () {
519+
}
520+
};
521+
let sandbox = sinon.sandbox.create();
522+
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
523+
({
524+
success: false,
525+
identity: {
526+
privacy: {optout: false},
527+
id: 'testId',
528+
keyv: 4
529+
}
530+
})
531+
);
532+
533+
let request = spec.buildRequests(bidRequests, {});
534+
let data = JSON.parse(request.data);
535+
expect(data.user.eids).to.deep.equal(undefined);
536+
sandbox.restore();
537+
delete window.DigiTrust;
538+
});
539+
540+
describe('DigiTrustId from config', function() {
541+
var origGetConfig;
542+
let sandbox;
543+
beforeEach(() => {
544+
sandbox = sinon.sandbox.create();
545+
window.DigiTrust = {
546+
getUser: sandbox.spy()
547+
};
548+
});
549+
550+
afterEach(() => {
551+
sandbox.restore();
552+
delete window.DigiTrust;
553+
});
554+
555+
it('Request should have digiTrustId config params', function() {
556+
sandbox.stub(config, 'getConfig').callsFake((key) => {
557+
var config = {
558+
digiTrustId: {
559+
success: true,
560+
identity: {
561+
privacy: {optout: false},
562+
id: 'testId',
563+
keyv: 4
564+
}
565+
}
566+
};
567+
return config[key];
568+
});
569+
570+
let request = spec.buildRequests(bidRequests, {});
571+
let data = JSON.parse(request.data);
572+
expect(data.user.eids).to.deep.equal([{
573+
'source': 'digitru.st',
574+
'uids': [{
575+
'id': 'testId',
576+
'atype': 1,
577+
'ext': {
578+
'keyv': 4
579+
}
580+
}]
581+
}]);
582+
// should not have called DigiTrust.getUser()
583+
expect(window.DigiTrust.getUser.notCalled).to.equal(true);
584+
});
585+
586+
it('Request should not have digiTrustId config params due to optout', function() {
587+
sandbox.stub(config, 'getConfig').callsFake((key) => {
588+
var config = {
589+
digiTrustId: {
590+
success: true,
591+
identity: {
592+
privacy: {optout: true},
593+
id: 'testId',
594+
keyv: 4
595+
}
596+
}
597+
}
598+
return config[key];
599+
});
600+
let request = spec.buildRequests(bidRequests, {});
601+
let data = JSON.parse(request.data);
602+
expect(data.user.eids).to.deep.equal(undefined);
603+
// should not have called DigiTrust.getUser()
604+
expect(window.DigiTrust.getUser.notCalled).to.equal(true);
605+
});
606+
607+
it('Request should not have digiTrustId config params due to failure', function() {
608+
sandbox.stub(config, 'getConfig').callsFake((key) => {
609+
var config = {
610+
digiTrustId: {
611+
success: false,
612+
identity: {
613+
privacy: {optout: false},
614+
id: 'testId',
615+
keyv: 4
616+
}
617+
}
618+
}
619+
return config[key];
620+
});
621+
622+
let request = spec.buildRequests(bidRequests, {});
623+
let data = JSON.parse(request.data);
624+
expect(data.user.eids).to.deep.equal(undefined);
625+
// should not have called DigiTrust.getUser()
626+
expect(window.DigiTrust.getUser.notCalled).to.equal(true);
627+
});
628+
629+
it('Request should not have digiTrustId config params if they do not exist', function() {
630+
sandbox.stub(config, 'getConfig').callsFake((key) => {
631+
var config = {};
632+
return config[key];
633+
});
634+
635+
let request = spec.buildRequests(bidRequests, {});
636+
let data = JSON.parse(request.data);
637+
expect(data.user.eids).to.deep.equal(undefined);
638+
// should have called DigiTrust.getUser() once
639+
expect(window.DigiTrust.getUser.calledOnce).to.equal(true);
640+
});
641+
});
642+
451643
it('Request params check for video ad', function () {
452644
let request = spec.buildRequests(videoBidRequests);
453645
let data = JSON.parse(request.data);

0 commit comments

Comments
 (0)