Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubMatic to support DigiTrust Id passing #3160

Merged
merged 7 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER, VIDEO } from 'src/mediaTypes';
import {config} from 'src/config';
const constants = require('src/constants.json');

const BIDDER_CODE = 'pubmatic';
const ENDPOINT = '//hbopenbid.pubmatic.com/translator?source=prebid-client';
const USYNCURL = '//ads.pubmatic.com/AdServer/js/showad.js#PIX&kdntuid=1&p=';
const DEFAULT_CURRENCY = 'USD';
const AUCTION_TYPE = 1;
const PUBMATIC_DIGITRUST_KEY = 'nFIn8aLzbd';
const UNDEFINED = undefined;
const CUSTOM_PARAMS = {
'kadpageurl': '', // Custom page url
Expand Down Expand Up @@ -275,6 +277,46 @@ function _createImpressionObject(bid, conf) {
return impObj;
}

function _getDigiTrustObject(key) {
function getDigiTrustId() {
let digiTrustUser = window.DigiTrust && (config.getConfig('digiTrustId') || window.DigiTrust.getUser({member: key}));
return (digiTrustUser && digiTrustUser.success && digiTrustUser.identity) || null;
}
let digiTrustId = getDigiTrustId();
// Verify there is an ID and this user has not opted out
if (!digiTrustId || (digiTrustId.privacy && digiTrustId.privacy.optout)) {
return null;
}
return digiTrustId;
}

function _handleDigitrustId(eids) {
let digiTrustId = _getDigiTrustObject(PUBMATIC_DIGITRUST_KEY);
if (digiTrustId !== null) {
eids.push({
'source': 'digitru.st',
'uids': [
{
'id': digiTrustId.id || '',
'atype': 1,
'ext': {
'keyv': parseInt(digiTrustId.keyv) || 0
}
}
]
});
}
}

function _handleEids(payload) {
let eids = [];
_handleDigitrustId(eids);
if (eids.length > 0) {
// todo: are we sure we have to send this data at user.eids or user.ext.each_eid_solution_object?
payload.user.eids = eids;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify - is this still an open question? Or has it been confirmed?

If the latter, can you remove the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @jsnellbaker ,
I have removed the comment now.

}
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
Expand Down Expand Up @@ -414,6 +456,8 @@ export const spec = {
utils.logWarn(BIDDER_CODE + ': dctr value not found in 1st adunit, ignoring values from subsequent adunits');
}

_handleEids(payload);

return {
method: 'POST',
url: ENDPOINT,
Expand Down
192 changes: 192 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {expect} from 'chai';
import {spec} from 'modules/pubmaticBidAdapter';
import * as utils from 'src/utils';
import {config} from 'src/config';
const constants = require('src/constants.json');

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

it('Request should have digitrust params', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the arrow functions in the various test functions to use the , function() { syntax? This is more in-line with Mocha's style/expectations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made these changes now.

window.DigiTrust = {
getUser: function () {
}
};
var bidRequest = {};
let sandbox = sinon.sandbox.create();
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
({
success: true,
identity: {
privacy: {optout: false},
id: 'testId',
keyv: 4
}
})
);

let request = spec.buildRequests(bidRequests, bidRequest);
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal([{
'source': 'digitru.st',
'uids': [{
'id': 'testId',
'atype': 1,
'ext': {
'keyv': 4
}
}]
}]);
sandbox.restore();
delete window.DigiTrust;
});

it('Request should not have digitrust params when DigiTrust not loaded', () => {
let request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
});

it('Request should not have digitrust params due to optout', () => {
window.DigiTrust = {
getUser: function () {
}
};
let sandbox = sinon.sandbox.create();
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
({
success: true,
identity: {
privacy: {optout: true},
id: 'testId',
keyv: 4
}
})
);

let request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
sandbox.restore();
delete window.DigiTrust;
});

it('Request should not have digitrust params due to failure', () => {
window.DigiTrust = {
getUser: function () {
}
};
let sandbox = sinon.sandbox.create();
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
({
success: false,
identity: {
privacy: {optout: false},
id: 'testId',
keyv: 4
}
})
);

let request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
sandbox.restore();
delete window.DigiTrust;
});

describe('DigiTrustId from config', () => {
var origGetConfig;
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox.create();
window.DigiTrust = {
getUser: sandbox.spy()
};
});

afterEach(() => {
sandbox.restore();
delete window.DigiTrust;
});

it('Request should have digiTrustId config params', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
digiTrustId: {
success: true,
identity: {
privacy: {optout: false},
id: 'testId',
keyv: 4
}
}
};
return config[key];
});

let request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal([{
'source': 'digitru.st',
'uids': [{
'id': 'testId',
'atype': 1,
'ext': {
'keyv': 4
}
}]
}]);
// should not have called DigiTrust.getUser()
expect(window.DigiTrust.getUser.notCalled).to.equal(true);
});

it('Request should not have digiTrustId config params due to optout', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
digiTrustId: {
success: true,
identity: {
privacy: {optout: true},
id: 'testId',
keyv: 4
}
}
}
return config[key];
});
let request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
// should not have called DigiTrust.getUser()
expect(window.DigiTrust.getUser.notCalled).to.equal(true);
});

it('Request should not have digiTrustId config params due to failure', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
digiTrustId: {
success: false,
identity: {
privacy: {optout: false},
id: 'testId',
keyv: 4
}
}
}
return config[key];
});

let request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
// should not have called DigiTrust.getUser()
expect(window.DigiTrust.getUser.notCalled).to.equal(true);
});

it('Request should not have digiTrustId config params if they do not exist', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {};
return config[key];
});

let request = spec.buildRequests(bidRequests, {});
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal(undefined);
// should have called DigiTrust.getUser() once
expect(window.DigiTrust.getUser.calledOnce).to.equal(true);
});
});

it('Request params check for video ad', function () {
let request = spec.buildRequests(videoBidRequests);
let data = JSON.parse(request.data);
Expand Down