Skip to content

Commit

Permalink
Updated IX Adapter (prebid#3744)
Browse files Browse the repository at this point in the history
* Added Support For Identity

    * Added Tests For Identity
  • Loading branch information
ix-prebid-development authored and jacekburys-quantcast committed May 15, 2019
1 parent 3e17c11 commit 8242f0d
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 4 deletions.
28 changes: 24 additions & 4 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ export const spec = {
*/
buildRequests: function (validBidRequests, options) {
const bannerImps = [];
const userEids = [];
let validBidRequest = null;
let bannerImp = null;

// Always start by assuming the protocol is HTTPS. This way, it will work
// whether the page protocol is HTTP or HTTPS. Then check if the page is
// actually HTTP.If we can guarantee it is, then, and only then, set protocol to
Expand All @@ -201,6 +203,21 @@ export const spec = {
bannerImps.push(bannerImp);
}

// RTI ids will be included in the bid request if the function getIdentityInfo() is loaded
// and if the data for the partner exist
if (window.headertag && typeof window.headertag.getIdentityInfo === 'function') {
let identityInfo = window.headertag.getIdentityInfo();
if (identityInfo && typeof identityInfo === 'object') {
for (const partnerName in identityInfo) {
if (identityInfo.hasOwnProperty(partnerName)) {
let response = identityInfo[partnerName];
if (!response.responsePending && response.data && typeof response.data === 'object' && Object.keys(response.data).length) {
userEids.push(response.data);
}
}
}
}
}
const r = {};

// Since bidderRequestId are the same for different bid request, just use the first one.
Expand All @@ -210,6 +227,10 @@ export const spec = {
r.site = {};
r.ext = {};
r.ext.source = 'prebid';
if (userEids.length > 0) {
r.user = {};
r.user.eids = userEids;
}

if (document.referrer && document.referrer !== '') {
r.site.ref = document.referrer;
Expand All @@ -229,10 +250,9 @@ export const spec = {
}

if (gdprConsent.hasOwnProperty('consentString')) {
r.user = {
ext: {
consent: gdprConsent.consentString || ''
}
r.user = r.user || {};
r.user.ext = {
consent: gdprConsent.consentString || ''
};
}
}
Expand Down
178 changes: 178 additions & 0 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ describe('IndexexchangeAdapter', function () {
}
]
};
const DEFAULT_IDENTITY_RESPONSE = {
IdentityIp: {
responsePending: false,
data: {
source: 'identityinc.com',
uids: [
{
id: 'identityid'
}
]
}
}
};

describe('inherited functions', function () {
it('should exists and is a function', function () {
Expand Down Expand Up @@ -209,6 +222,171 @@ describe('IndexexchangeAdapter', function () {
});
});

describe('buildRequestsIdentity', function () {
let request;
let query;
let testCopy;

beforeEach(function() {
window.headertag = {};
window.headertag.getIdentityInfo = function() {
return testCopy;
};
request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
query = request.data;
});
afterEach(function() {
delete window.headertag;
});
describe('buildRequestSingleRTI', function() {
before(function() {
testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE));
});
it('payload should have correct format and value (single identity partner)', function () {
const payload = JSON.parse(query.r);

expect(payload.user).to.exist;
expect(payload.user.eids).to.exist;
expect(payload.user.eids).to.be.an('array');
expect(payload.user.eids).to.have.lengthOf(1);
});

it('identity data in impression should have correct format and value (single identity partner)', function () {
const impression = JSON.parse(query.r).user.eids;
expect(impression[0].source).to.equal(testCopy.IdentityIp.data.source);
expect(impression[0].uids[0].id).to.equal(testCopy.IdentityIp.data.uids[0].id);
});
});

describe('buildRequestMultipleIds', function() {
before(function() {
testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE));
testCopy.IdentityIp.data.uids.push({
id: '1234567'
},
{
id: '2019-04-01TF2:34:41'
});
});
it('payload should have correct format and value (single identity w/ multi ids)', function () {
const payload = JSON.parse(query.r);

expect(payload.user).to.exist;
expect(payload.user.eids).to.exist;
expect(payload.user.eids).to.be.an('array');
expect(payload.user.eids).to.have.lengthOf(1);
});

it('identity data in impression should have correct format and value (single identity w/ multi ids)', function () {
const impression = JSON.parse(query.r).user.eids;

expect(impression[0].source).to.equal(testCopy.IdentityIp.data.source);
expect(impression[0].uids).to.have.lengthOf(3);
});
});

describe('buildRequestMultipleRTI', function() {
before(function() {
testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE));
testCopy.JackIp = {
responsePending: false,
data: {
source: 'jackinc.com',
uids: [
{
id: 'jackid'
}
]
}
}
testCopy.GenericIp = {
responsePending: false,
data: {
source: 'genericip.com',
uids: [
{
id: 'genericipenvelope'
}
]
}
}
});
it('payload should have correct format and value (multiple identity partners)', function () {
const payload = JSON.parse(query.r);

expect(payload.user).to.exist;
expect(payload.user.eids).to.exist;
expect(payload.user.eids).to.be.an('array');
expect(payload.user.eids).to.have.lengthOf(3);
});

it('identity data in impression should have correct format and value (multiple identity partners)', function () {
const impression = JSON.parse(query.r).user.eids;

expect(impression[0].source).to.equal(testCopy.IdentityIp.data.source);
expect(impression[0].uids).to.have.lengthOf(1);

expect(impression[1].source).to.equal(testCopy.JackIp.data.source);
expect(impression[1].uids).to.have.lengthOf(1);

expect(impression[2].source).to.equal(testCopy.GenericIp.data.source);
expect(impression[2].uids).to.have.lengthOf(1);
});
});

describe('buildRequestNoData', function() {
beforeEach(function() {
testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE));
});

it('payload should not have any user eids with an undefined identity data response', function () {
window.headertag.getIdentityInfo = function() {
return undefined;
};
request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
query = request.data;
const payload = JSON.parse(query.r);

expect(payload.user).to.exist;
expect(payload.user.eids).to.not.exist;
});

it('payload should have user eids if least one partner data is available', function () {
testCopy.GenericIp = {
responsePending: true,
data: {}
}
request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
query = request.data;
const payload = JSON.parse(query.r);

expect(payload.user).to.exist;
expect(payload.user.eids).to.exist;
});

it('payload should not have any user eids if identity data is pending for all partners', function () {
testCopy.IdentityIp.responsePending = true;
request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
query = request.data;
const payload = JSON.parse(query.r);

expect(payload.user).to.exist;
expect(payload.user.eids).to.not.exist;
});

it('payload should not have any user eids if identity data is pending or not available for all partners', function () {
testCopy.IdentityIp.responsePending = false;
testCopy.IdentityIp.data = {};
request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
query = request.data;
const payload = JSON.parse(query.r);

expect(payload.user).to.exist;
expect(payload.user.eids).to.not.exist;
});
});
});

describe('buildRequestsBanner', function () {
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
const requestUrl = request.url;
Expand Down

0 comments on commit 8242f0d

Please sign in to comment.