diff --git a/modules/bidfluenceBidAdapter.js b/modules/bidfluenceBidAdapter.js index 655e52e2d6d..31c581276f1 100644 --- a/modules/bidfluenceBidAdapter.js +++ b/modules/bidfluenceBidAdapter.js @@ -36,67 +36,79 @@ export const spec = { }, buildRequests: function (validBidRequests, bidderRequest) { - return validBidRequests.map(bidRequest => { - const params = bidRequest.params; - const sizes = utils.parseSizesInput(bidRequest.sizes)[0]; - const width = sizes.split('x')[0]; - const height = sizes.split('x')[1]; - const refInfo = bidderRequest.refererInfo; - const gdpr = bidderRequest.gdprConsent; - const body = document.getElementsByTagName('body')[0]; - const vpW = Math.max(window.innerWidth || body.clientWidth || 0) + 2; - const vpH = Math.max(window.innerHeight || body.clientHeight || 0) + 2; - const sr = screen.height > screen.width ? screen.height + 'x' + screen.width + 'x' + screen.colorDepth : screen.width + 'x' + screen.height + 'x' + screen.colorDepth; + const body = document.getElementsByTagName('body')[0]; + const refInfo = bidderRequest.refererInfo; + const gdpr = bidderRequest.gdprConsent; + const vpW = Math.max(window.innerWidth || body.clientWidth || 0) + 2; + const vpH = Math.max(window.innerHeight || body.clientHeight || 0) + 2; + const sr = screen.height > screen.width ? screen.height + 'x' + screen.width + 'x' + screen.colorDepth : screen.width + 'x' + screen.height + 'x' + screen.colorDepth; - const payload = { + var payload = { + v: '2.0', + azr: true, + ck: utils.cookiesAreEnabled(), + re: refInfo ? refInfo.referer : '', + st: refInfo ? refInfo.stack : [], + tz: getBdfTz(new Date()), + sr: sr, + tm: bidderRequest.timeout, + vp: vpW + 'x' + vpH, + sdt: getUTCDate(), + top: refInfo ? refInfo.reachedTop : false, + gdpr: gdpr ? gdpr.gdprApplies : false, + gdprc: gdpr ? gdpr.consentString : '', + bids: [] + }; + + utils._each(validBidRequests, function (bidRequest) { + var params = bidRequest.params; + var sizes = utils.parseSizesInput(bidRequest.sizes)[0]; + var width = sizes.split('x')[0]; + var height = sizes.split('x')[1]; + + var currentBidPayload = { bid: bidRequest.bidId, - v: '1.0', - azr: true, - ck: utils.cookiesAreEnabled(), tid: params.placementId, pid: params.publisherId, rp: params.reservePrice || 0, - re: refInfo ? refInfo.referer : '', - st: refInfo ? refInfo.stack : [], - tz: getBdfTz(new Date()), - sr: sr, - tm: bidderRequest.timeout, - vp: vpW + 'x' + vpH, - sdt: getUTCDate(), w: width, - h: height, - gdpr: gdpr ? gdpr.gdprApplies : false, - gdprc: gdpr ? gdpr.consentString : '' - }; - const payloadString = JSON.stringify(payload); - return { - method: 'POST', - url: `//${payload.pid}.bidfluence.com/Hb`, - data: payloadString, - options: { contentType: 'text/plain' } + h: height }; + + payload.bids.push(currentBidPayload); }); + + const payloadString = JSON.stringify(payload); + return { + method: 'POST', + url: `//bdf${payload.bids[0].pid}.bidfluence.com/Prebid`, + data: payloadString, + options: { contentType: 'text/plain' } + }; }, interpretResponse: function (serverResponse, bidRequest) { const bidResponses = []; const response = serverResponse.body; - const cpm = response.Cpm || 0; - if (cpm > 0) { - const bidResponse = { - requestId: response.BidId, - cpm: cpm, - width: response.Width, - height: response.Height, - creativeId: response.CreativeId, - ad: response.Ad, - currency: 'USD', - netRevenue: true, - ttl: 360 - }; - bidResponses.push(bidResponse); - } + utils._each(response.Bids, function (currentResponse) { + var cpm = currentResponse.Cpm || 0; + + if (cpm > 0) { + const bidResponse = { + requestId: currentResponse.BidId, + cpm: cpm, + width: currentResponse.Width, + height: currentResponse.Height, + creativeId: currentResponse.CreativeId, + ad: currentResponse.Ad, + currency: 'USD', + netRevenue: true, + ttl: 360 + }; + bidResponses.push(bidResponse); + } + }); return bidResponses; }, diff --git a/test/spec/modules/bidfluenceBidAdapter_spec.js b/test/spec/modules/bidfluenceBidAdapter_spec.js index 71471c6650b..9ce6e808c6b 100644 --- a/test/spec/modules/bidfluenceBidAdapter_spec.js +++ b/test/spec/modules/bidfluenceBidAdapter_spec.js @@ -54,25 +54,25 @@ describe('Bidfluence Adapter test', () => { const request = spec.buildRequests(validBidRequests, bidderRequest); it('sends bid request to our endpoint via POST', function () { - expect(request[0].method).to.equal('POST'); + expect(request.method).to.equal('POST'); }); - const payload = JSON.parse(request[0].data); + const payload = JSON.parse(request.data); - expect(payload.bid).to.equal(validBidRequests[0].bidId); + expect(payload.bids[0].bid).to.equal(validBidRequests[0].bidId); expect(payload.azr).to.equal(true); expect(payload.ck).to.not.be.undefined; - expect(payload.tid).to.equal(PLACEMENT_ID); - expect(payload.pid).to.equal(PUB_ID); - expect(payload.rp).to.be.a('number'); + expect(payload.bids[0].tid).to.equal(PLACEMENT_ID); + expect(payload.bids[0].pid).to.equal(PUB_ID); + expect(payload.bids[0].rp).to.be.a('number'); expect(payload.re).to.not.be.undefined; expect(payload.st).to.not.be.undefined; expect(payload.tz).to.not.be.undefined; expect(payload.sr).to.not.be.undefined; expect(payload.vp).to.not.be.undefined; expect(payload.sdt).to.not.be.undefined; - expect(payload.w).to.equal('300'); - expect(payload.h).to.equal('250'); + expect(payload.bids[0].w).to.equal('300'); + expect(payload.bids[0].h).to.equal('250'); it('sends gdpr info if exists', function () { expect(payload.gdpr).to.equal(true); @@ -83,22 +83,25 @@ describe('Bidfluence Adapter test', () => { describe('interpretResponse', function () { const response = { body: { - 'CreativeId': '1000', - 'Cpm': 0.50, - 'Ad': '
', - 'Height': 250, - 'Width': 300 + Bids: + [{ + 'CreativeId': '1000', + 'Cpm': 0.50, + 'Ad': '', + 'Height': 250, + 'Width': 300 + }] } }; it('should get correct bid response', function () { const expectedResponse = [{ - requestId: response.body.BidId, - cpm: response.body.Cpm, - width: response.body.Width, - height: response.body.Height, - creativeId: response.body.CreativeId, - ad: response.body.Ad, + requestId: response.body.Bids[0].BidId, + cpm: response.body.Bids[0].Cpm, + width: response.body.Bids[0].Width, + height: response.body.Bids[0].Height, + creativeId: response.body.Bids[0].CreativeId, + ad: response.body.Bids[0].Ad, currency: 'USD', netRevenue: true, ttl: 360