Skip to content

Commit

Permalink
Triplelift adapter tdid support (#3983)
Browse files Browse the repository at this point in the history
* Add user support in _buildPostBody

* Add tdid check to test spec

* Remove comments

* Removing package-lock.json changes
  • Loading branch information
rmcnierney authored and jaiminpanchal27 committed Jul 16, 2019
1 parent 08fd1a5 commit 406d2a5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
28 changes: 26 additions & 2 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);
let data = _buildPostBody(bidRequests, bidderRequest);

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) {
function _buildPostBody(bidRequests, bidderRequest) {
let data = {};
data.imp = bidRequests.map(function(bid, index) {
return {
Expand All @@ -91,6 +91,13 @@ function _buildPostBody(bidRequests) {
}
});

let eids = handleConsortiaUserIds(bidderRequest)
if (eids.length > 0) {
data.user = {
ext: {eids}
}
}

return data;
}

Expand All @@ -108,6 +115,23 @@ 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
10 changes: 10 additions & 0 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ describe('triplelift adapter', function () {
gdprConsent: {
consentString: 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY',
gdprApplies: true
},
userId: {
tdid: '6bca7f6b-a98a-46c0-be05-6020f7604598'
}
};

Expand All @@ -112,6 +115,13 @@ describe('triplelift adapter', function () {
expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]);
});

it('should add tdid to the payload if included', function () {
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'}}]}]}});
});

it('should return a query string for TL call', function () {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
const url = request.url;
Expand Down

0 comments on commit 406d2a5

Please sign in to comment.