Skip to content

Commit

Permalink
TripleLift support for UnifiedId and IdentityLink (prebid#4197)
Browse files Browse the repository at this point in the history
* Add IdentityLink support and fix UnifiedId.

It appears we've been looking for UnifiedId userIds
on the bidderRequest object, when they are found on bidRequests.
This commit fixes that error, and adds support for IdentityLink.

* change maintainer email to group
  • Loading branch information
willchapin authored and sa1omon committed Nov 28, 2019
1 parent 258d100 commit 507d7b8
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 59 deletions.
56 changes: 36 additions & 20 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const tripleliftAdapterSpec = {

buildRequests: function(bidRequests, bidderRequest) {
let tlCall = STR_ENDPOINT;
let data = _buildPostBody(bidRequests, bidderRequest);
let data = _buildPostBody(bidRequests);

tlCall = utils.tryAppendQueryString(tlCall, 'lib', 'prebid');
tlCall = utils.tryAppendQueryString(tlCall, 'v', '$prebid.version$');
Expand Down Expand Up @@ -78,7 +78,7 @@ export const tripleliftAdapterSpec = {
}
}

function _buildPostBody(bidRequests, bidderRequest) {
function _buildPostBody(bidRequests) {
let data = {};
data.imp = bidRequests.map(function(bid, index) {
return {
Expand All @@ -91,7 +91,11 @@ function _buildPostBody(bidRequests, bidderRequest) {
};
});

let eids = handleConsortiaUserIds(bidderRequest);
let eids = [
...getUnifiedIdEids(bidRequests),
...getIdentityLinkEids(bidRequests)
];

if (eids.length > 0) {
data.user = {
ext: {eids}
Expand All @@ -101,6 +105,35 @@ function _buildPostBody(bidRequests, bidderRequest) {
return data;
}

function getUnifiedIdEids(bidRequests) {
return getEids(bidRequests, 'tdid', 'adserver.org', 'TDID');
}

function getIdentityLinkEids(bidRequests) {
return getEids(bidRequests, 'idl_env', 'liveramp.com', 'idl');
}

function getEids(bidRequests, type, source, rtiPartner) {
return bidRequests
.map(getUserId(type)) // bids -> userIds of a certain type
.filter((x) => !!x) // filter out null userIds
.map(formatEid(source, rtiPartner)); // userIds -> eid objects
}

function getUserId(type) {
return (bid) => (bid && bid.userId && bid.userId[type]);
}

function formatEid(source, rtiPartner) {
return (id) => ({
source,
uids: [{
id,
ext: { rtiPartner }
}]
});
}

function _sizes(sizeArray) {
let sizes = sizeArray.filter(_isValidSize);
return sizes.map(function(size) {
Expand All @@ -115,23 +148,6 @@ function _isValidSize(size) {
return (size.length === 2 && typeof size[0] === 'number' && typeof size[1] === 'number');
}

function handleConsortiaUserIds(bidderRequest) {
let eids = [];
if (bidderRequest.userId && bidderRequest.userId.tdid) {
eids.push({
source: 'adserver.org',
uids: [{
id: bidderRequest.userId.tdid,
ext: {
rtiPartner: 'TDID'
}
}]
});
}

return eids;
}

function _buildResponseObject(bidderRequest, bid) {
let bidResponse = {};
let width = bid.width || 1;
Expand Down
2 changes: 1 addition & 1 deletion modules/tripleliftBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
Module Name: Triplelift Bid Adapter
Module Type: Bidder Adapter
Maintainer: csmith+s2s@triplelift.com
Maintainer: prebid@triplelift.com
```

# Description
Expand Down
164 changes: 126 additions & 38 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,46 +54,49 @@ describe('triplelift adapter', function () {
});

describe('buildRequests', function () {
let bidRequests = [
{
bidder: 'triplelift',
params: {
inventoryCode: '12345',
floor: 1.0,
},
adUnitCode: 'adunit-code',
sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
}
];
let bidRequests;
let bidderRequest;

let bidderRequest = {
bidderCode: 'triplelift',
auctionId: 'a7ebcd1d-66ff-4b5c-a82c-6a21a6ee5a18',
bidderRequestId: '5c55612f99bc11',
bids: [
this.beforeEach(() => {
bidRequests = [
{
imp_id: 0,
cpm: 1.062,
width: 300,
height: 250,
ad: 'ad-markup',
iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg'
bidder: 'triplelift',
params: {
inventoryCode: '12345',
floor: 1.0,
},
adUnitCode: 'adunit-code',
sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
userId: {},
}
],
refererInfo: {
referer: 'http://examplereferer.com'
},
gdprConsent: {
consentString: 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY',
gdprApplies: true
},
userId: {
tdid: '6bca7f6b-a98a-46c0-be05-6020f7604598'
}
};
];

bidderRequest = {
bidderCode: 'triplelift',
auctionId: 'a7ebcd1d-66ff-4b5c-a82c-6a21a6ee5a18',
bidderRequestId: '5c55612f99bc11',
bids: [
{
imp_id: 0,
cpm: 1.062,
width: 300,
height: 250,
ad: 'ad-markup',
iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg'
}
],
refererInfo: {
referer: 'http://examplereferer.com'
},
gdprConsent: {
consentString: 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY',
gdprApplies: true
},
};
});

it('exists and is an object', function () {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
Expand All @@ -116,10 +119,95 @@ describe('triplelift adapter', function () {
});

it('should add tdid to the payload if included', function () {
const id = '6bca7f6b-a98a-46c0-be05-6020f7604598';
bidRequests[0].userId.tdid = id;
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
expect(payload).to.exist;
expect(payload.user).to.deep.equal({ext: {eids: [{source: 'adserver.org', uids: [{id, ext: {rtiPartner: 'TDID'}}]}]}});
});

it('should add idl_env to the payload if included', function () {
const id = 'XY6104gr0njcH9UDIR7ysFFJcm2XNpqeJTYslleJ_cMlsFOfZI';
bidRequests[0].userId.idl_env = id;
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
expect(payload).to.exist;
expect(payload.user).to.deep.equal({ext: {eids: [{source: 'liveramp.com', uids: [{id, ext: {rtiPartner: 'idl'}}]}]}});
});

it('should add both tdid and idl_env to the payload if both are included', function () {
const tdidId = '6bca7f6b-a98a-46c0-be05-6020f7604598';
const idlEnvId = 'XY6104gr0njcH9UDIR7ysFFJcm2XNpqeJTYslleJ_cMlsFOfZI';
bidRequests[0].userId.tdid = tdidId;
bidRequests[0].userId.idl_env = idlEnvId;

const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;

expect(payload).to.exist;
expect(payload.user).to.deep.equal({ext: {eids: [{source: 'adserver.org', uids: [{id: '6bca7f6b-a98a-46c0-be05-6020f7604598', ext: {rtiPartner: 'TDID'}}]}]}});
expect(payload.user).to.deep.equal({
ext: {
eids: [
{
source: 'adserver.org',
uids: [
{
id: tdidId,
ext: { rtiPartner: 'TDID' }
}
],
},
{
source: 'liveramp.com',
uids: [
{
id: idlEnvId,
ext: { rtiPartner: 'idl' }
}
]
}
]
}
});
});

it('should add user ids from multiple bid requests', function () {
const tdidId = '6bca7f6b-a98a-46c0-be05-6020f7604598';
const idlEnvId = 'XY6104gr0njcH9UDIR7ysFFJcm2XNpqeJTYslleJ_cMlsFOfZI';

const bidRequestsMultiple = [
{ ...bidRequests[0], userId: { tdid: tdidId } },
{ ...bidRequests[0], userId: { idl_env: idlEnvId } },
];

const request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest);
const payload = request.data;

expect(payload.user).to.deep.equal({
ext: {
eids: [
{
source: 'adserver.org',
uids: [
{
id: tdidId,
ext: { rtiPartner: 'TDID' }
}
],
},
{
source: 'liveramp.com',
uids: [
{
id: idlEnvId,
ext: { rtiPartner: 'idl' }
}
]
}
]
}
});
});

it('should return a query string for TL call', function () {
Expand Down

0 comments on commit 507d7b8

Please sign in to comment.