Skip to content

Commit

Permalink
Adnuntius Bid Adapter: Bug fix ordered response. (#6625)
Browse files Browse the repository at this point in the history
* Added automatic tzo and targetId to adserver request.

* Fixing issues with bid price being too low.

* Fixing issues with bid price being too low.

* Ad server response places bids in correct placement

* Adnuntius Bid Adapter ordered responses

* Ad server response places bids in correct placement

* Adnuntius Bid Adapter ordered responses

* RTD Provider rebase

* wrongly merged to master
  • Loading branch information
mikael-lundin authored Apr 20, 2021
1 parent 7635599 commit 649035b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
50 changes: 28 additions & 22 deletions modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'adnuntius';
const ENDPOINT_URL = 'https://delivery.adnuntius.com/i?tzo=';

export const spec = {
code: BIDDER_CODE,

isBidRequestValid: function (bid) {
return !!(bid.params.auId || (bid.params.member && bid.params.invCode));
return !!(bid.bidId || (bid.params.member && bid.params.invCode));
},

buildRequests: function (validBidRequests) {
Expand Down Expand Up @@ -42,28 +42,34 @@ export const spec = {
},

interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const serverBody = serverResponse.body;

for (var k = 0; k < serverBody.adUnits.length; k++) {
const adUnit = serverBody.adUnits[k]
if (adUnit.matchedAdCount > 0) {
const adUnits = serverResponse.body.adUnits;
const bidResponsesById = adUnits.reduce((response, adUnit) => {
if (adUnit.matchedAdCount >= 1) {
const bid = adUnit.ads[0];
const effectiveCpm = (bid.cpc && bid.cpm) ? bid.bid.amount + bid.cpm.amount : (bid.cpc) ? bid.bid.amount : (bid.cpm) ? bid.cpm.amount : 0;
bidResponses.push({
requestId: bidRequest.bid[k].bidId,
cpm: effectiveCpm,
width: Number(bid.creativeWidth),
height: Number(bid.creativeHeight),
creativeId: bid.creativeId,
currency: (bid.bid) ? bid.bid.currency : 'EUR',
netRevenue: false,
ttl: 360,
ad: adUnit.html
});
}
}
return bidResponses;
return {
...response,
[adUnit.targetId]: {
requestId: adUnit.targetId,
cpm: effectiveCpm,
width: Number(bid.creativeWidth),
height: Number(bid.creativeHeight),
creativeId: bid.creativeId,
currency: (bid.bid) ? bid.bid.currency : 'EUR',
netRevenue: false,
ttl: 360,
ad: adUnit.html
}
}
} else return response
}, {});

const bidResponse = bidRequest.bid.map(bid => bid.bidId)
.reduce((request, adunitId) =>
request.concat(bidResponsesById[adunitId])
, []);

return bidResponse
},

}
Expand Down
20 changes: 14 additions & 6 deletions test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@ describe('adnuntiusBidAdapter', function () {
const tzo = new Date().getTimezoneOffset();
const ENDPOINT_URL = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json`;
const adapter = newBidder(spec);

const bidRequests = [
{
bidId: '123',
bidder: 'adnuntius',
params: {
auId: '8b6bc',
network: 'adnuntius',
},
bidId: '123'

}
];
]

const singleBidRequest = {
bid: [
{
bidId: '123',
}
]
}

const serverResponse = {
body: {
'adUnits': [
{
'auId': '000000000008b6bc',
'targetId': '',
'targetId': '123',
'html': '<h1>hi!</h1>',
'matchedAdCount': 1,
'responseId': 'adn-rsp-1460129238',
Expand Down Expand Up @@ -103,10 +113,8 @@ describe('adnuntiusBidAdapter', function () {

describe('interpretResponse', function () {
it('should return valid response when passed valid server response', function () {
const request = spec.buildRequests(bidRequests);
const interpretedResponse = spec.interpretResponse(serverResponse, request[0]);
const interpretedResponse = spec.interpretResponse(serverResponse, singleBidRequest);
const ad = serverResponse.body.adUnits[0].ads[0]
const cpm = (ad.cpc && ad.cpm) ? ad.bid.amount + ad.cpm.amount : (ad.cpm) ? ad.cpm.amount : 0;

expect(interpretedResponse).to.have.lengthOf(1);
expect(interpretedResponse[0].cpm).to.equal(ad.cpm.amount);
Expand Down

0 comments on commit 649035b

Please sign in to comment.