Skip to content

Commit

Permalink
Bidfluence Adapter update - Single call (prebid#3347)
Browse files Browse the repository at this point in the history
* Bidfluence Adapter update

Support single call to server for all bids

* Bidfluence Adapter update

Support single call to server for all bids - relative to adapter update
  • Loading branch information
francescocristallo authored and Loic Talon committed Dec 19, 2018
1 parent 50cee98 commit b3e670c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 66 deletions.
106 changes: 59 additions & 47 deletions modules/bidfluenceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
41 changes: 22 additions & 19 deletions test/spec/modules/bidfluenceBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -83,22 +83,25 @@ describe('Bidfluence Adapter test', () => {
describe('interpretResponse', function () {
const response = {
body: {
'CreativeId': '1000',
'Cpm': 0.50,
'Ad': '<div></div>',
'Height': 250,
'Width': 300
Bids:
[{
'CreativeId': '1000',
'Cpm': 0.50,
'Ad': '<div></div>',
'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
Expand Down

0 comments on commit b3e670c

Please sign in to comment.