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

Vidazoo Adapter: Feature/user-id #5386

Merged
merged 8 commits into from Jun 23, 2020
Merged
37 changes: 36 additions & 1 deletion modules/vidazooBidAdapter.js
Expand Up @@ -14,14 +14,26 @@ const EXTERNAL_SYNC_TYPE = {
IFRAME: 'iframe',
IMAGE: 'image'
};
export const SUPPORTED_ID_SYSTEMS = {
'britepoolid': 1,
'criteoId': 1,
'digitrustid': 1,
'id5id': 1,
'idl_env': 1,
'lipb': 1,
'netId': 1,
'parrableid': 1,
'pubcid': 1,
'tdid': 1,
};

function isBidRequestValid(bid) {
const params = bid.params || {};
return !!(params.cId && params.pId);
}

function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
const { params, bidId } = bid;
const { params, bidId, userId } = bid;
const { bidFloor, cId, pId, ext } = params;
const hashUrl = hashCode(topWindowUrl);
const dealId = getNextDealId(hashUrl);
Expand All @@ -35,6 +47,9 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
sizes: sizes,
dealId: dealId,
};

appendUserIdsToRequestPayload(data, userId);

if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString) {
data.gdprConsent = bidderRequest.gdprConsent.consentString;
Expand All @@ -59,6 +74,26 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
return dto;
}

function appendUserIdsToRequestPayload(payloadRef, userIds) {
let key;
utils._each(userIds, (userId, idSystemProviderName) => {
if (SUPPORTED_ID_SYSTEMS[idSystemProviderName]) {
key = `uid.${idSystemProviderName}`;

switch (idSystemProviderName) {
case 'digitrustid':
payloadRef[key] = utils.deepAccess(userId, 'data.id');
break;
case 'lipb':
payloadRef[key] = userId.lipbid;
break;
default:
payloadRef[key] = userId;
}
}
});
}

function buildRequests(validBidRequests, bidderRequest) {
const topWindowUrl = bidderRequest.refererInfo.referer;
const requests = [];
Expand Down
26 changes: 25 additions & 1 deletion test/spec/modules/vidazooBidAdapter_spec.js
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec as adapter, URL } from 'modules/vidazooBidAdapter.js';
import { spec as adapter, URL, SUPPORTED_ID_SYSTEMS } from 'modules/vidazooBidAdapter.js';
import * as utils from 'src/utils.js';

const BID = {
Expand Down Expand Up @@ -210,4 +210,28 @@ describe('VidazooBidAdapter', function () {
expect(responses[0].ttl).to.equal(300);
});
});

describe(`user id system`, function () {
Object.keys(SUPPORTED_ID_SYSTEMS).forEach((idSystemProvider) => {
const id = Date.now().toString();
const bid = utils.deepClone(BID);

const userId = (function () {
switch (idSystemProvider) {
case 'digitrustid': return { data: { id: id } };
case 'lipb': return { lipbid: id };
default: return id;
}
})();

bid.userId = {
[idSystemProvider]: userId
};

it(`should include 'uid.${idSystemProvider}' in request params`, function () {
const requests = adapter.buildRequests([bid], BIDDER_REQUEST);
expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id);
});
});
});
});