diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index d6b1f95351d..b003de7785f 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -111,6 +111,8 @@ function _getSyncType(syncOptions) { function _buildPostBody(bidRequests) { let data = {}; let { schain } = bidRequests[0]; + const globalFpd = _getGlobalFpd(); + data.imp = bidRequests.map(function(bidRequest, index) { let imp = { id: index, @@ -137,10 +139,10 @@ function _buildPostBody(bidRequests) { }; } - if (schain) { - data.ext = { - schain - } + let ext = _getExt(schain, globalFpd); + + if (!utils.isEmpty(ext)) { + data.ext = ext; } return data; } @@ -172,6 +174,38 @@ function _getFloor (bid) { return floor !== null ? floor : bid.params.floor; } +function _getGlobalFpd() { + let fpd = {}; + const fpdContext = Object.assign({}, config.getConfig('fpd.context')); + const fpdUser = Object.assign({}, config.getConfig('fpd.user')); + + _addEntries(fpd, fpdContext); + _addEntries(fpd, fpdUser); + + return fpd; +} + +function _addEntries(target, source) { + if (!utils.isEmpty(source)) { + Object.keys(source).forEach(key => { + if (source[key] != null) { + target[key] = source[key]; + } + }); + } +} + +function _getExt(schain, fpd) { + let ext = {}; + if (!utils.isEmpty(schain)) { + ext.schain = { ...schain }; + } + if (!utils.isEmpty(fpd)) { + ext.fpd = { ...fpd }; + } + return ext; +} + function getUnifiedIdEids(bidRequests) { return getEids(bidRequests, 'tdid', 'adserver.org', 'TDID'); } @@ -239,13 +273,18 @@ function _buildResponseObject(bidderRequest, bid) { dealId: dealId, currency: 'USD', ttl: 300, - tl_source: bid.tl_source + tl_source: bid.tl_source, + meta: {} }; if (breq.mediaTypes.video) { bidResponse.vastXml = bid.ad; bidResponse.mediaType = 'video'; }; + + if (bid.advertiser_name) { + bidResponse.meta.advertiserName = bid.advertiser_name; + } }; return bidResponse; } diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index c6c3b622755..797b3fab0c1 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -4,6 +4,7 @@ import { newBidder } from 'src/adapters/bidderFactory.js'; import { deepClone } from 'src/utils.js'; import { config } from 'src/config.js'; import prebid from '../../../package.json'; +import * as utils from 'src/utils.js'; const ENDPOINT = 'https://tlx.3lift.com/header/auction?'; const GDPR_CONSENT_STR = 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY'; @@ -11,6 +12,7 @@ const GDPR_CONSENT_STR = 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7V describe('triplelift adapter', function () { const adapter = newBidder(tripleliftAdapterSpec); let bid, instreamBid; + let sandbox; this.beforeEach(() => { bid = { @@ -194,6 +196,10 @@ describe('triplelift adapter', function () { gdprApplies: true }, }; + sandbox = sinon.sandbox.create(); + }); + afterEach(() => { + sandbox.restore(); }); it('exists and is an object', function () { @@ -397,6 +403,31 @@ describe('triplelift adapter', function () { const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); expect(request.data.imp[0].floor).to.equal(1.99); }); + it('should send fpd on root level ext if kvps are available', function() { + const sens = null; + const category = ['news', 'weather', 'hurricane']; + const pmp_elig = 'true'; + const fpd = { + context: { + pmp_elig, + category, + }, + user: { + sens, + } + } + sandbox.stub(config, 'getConfig').callsFake(key => { + const config = { + fpd + }; + return utils.deepAccess(config, key); + }); + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); + const { data: payload } = request; + expect(payload.ext.fpd).to.not.haveOwnProperty('sens'); + expect(payload.ext.fpd).to.haveOwnProperty('category'); + expect(payload.ext.fpd).to.haveOwnProperty('pmp_elig'); + }); }); describe('interpretResponse', function () { @@ -413,6 +444,7 @@ describe('triplelift adapter', function () { ad: 'ad-markup', iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg', tl_source: 'tlx', + advertiser_name: 'fake advertiser name' }, { imp_id: 1, @@ -486,6 +518,7 @@ describe('triplelift adapter', function () { currency: 'USD', ttl: 33, tl_source: 'tlx', + meta: {} }, { requestId: '30b31c1838de1e', @@ -501,6 +534,7 @@ describe('triplelift adapter', function () { tl_source: 'hdx', mediaType: 'video', vastXml: 'The Trade Desk', + meta: {} } ]; let result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); @@ -513,6 +547,12 @@ describe('triplelift adapter', function () { let result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); expect(result).to.have.length(2); }); + + it('should include the advertiser name in the meta field if available', function () { + let result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); + expect(result[0].meta.advertiserName).to.equal('fake advertiser name') + expect(result[1].meta).to.not.have.key('advertiserName'); + }); }); describe('getUserSyncs', function() {