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

TripleLift: Sending schain #4375

Merged
merged 4 commits into from
Oct 25, 2019
Merged
Changes from 1 commit
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
Next Next commit
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.
  • Loading branch information
willchapin committed Sep 16, 2019

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 86546e9a51375bf6be11d28fef9bfde11f6a550c
56 changes: 36 additions & 20 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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$');
@@ -78,7 +78,7 @@ export const tripleliftAdapterSpec = {
}
}

function _buildPostBody(bidRequests, bidderRequest) {
function _buildPostBody(bidRequests) {
let data = {};
data.imp = bidRequests.map(function(bid, index) {
return {
@@ -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}
@@ -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) {
@@ -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;
164 changes: 126 additions & 38 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -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);
@@ -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 () {