Skip to content

Commit

Permalink
Multiple bids in one request to Adrino Adserver (prebid#9742)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Mielcarz <tomasz.mielcarz@adrino.pl>
  • Loading branch information
2 people authored and jorgeluisrocha committed May 18, 2023
1 parent 4fad7a5 commit 2a926e1
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 50 deletions.
40 changes: 24 additions & 16 deletions modules/adrinoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
const bidRequests = [];

let bids = [];
for (let i = 0; i < validBidRequests.length; i++) {
let host = this.getBidderConfig('host') || BIDDER_HOST;

let requestData = {
bidId: validBidRequests[i].bidId,
nativeParams: validBidRequests[i].nativeParams,
Expand All @@ -52,27 +50,37 @@ export const spec = {
}
}

bidRequests.push({
method: REQUEST_METHOD,
url: host + '/bidder/bid/',
data: requestData,
options: {
contentType: 'application/json',
withCredentials: false,
}
});
bids.push(requestData);
}

let host = this.getBidderConfig('host') || BIDDER_HOST;
let bidRequests = [];
bidRequests.push({
method: REQUEST_METHOD,
url: host + '/bidder/bids/',
data: bids,
options: {
contentType: 'application/json',
withCredentials: false,
}
});

return bidRequests;
},

interpretResponse: function (serverResponse, bidRequest) {
const response = serverResponse.body;
const bidResponses = [];
if (!response.noAd) {
bidResponses.push(response);
const output = [];

if (response.bidResponses) {
for (const bidResponse of response.bidResponses) {
if (!bidResponse.noAd) {
output.push(bidResponse);
}
}
}
return bidResponses;

return output;
},

onBidWon: function (bid) {
Expand Down
99 changes: 65 additions & 34 deletions test/spec/modules/adrinoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ describe('adrinoBidAdapter', function () {
);
expect(result.length).to.equal(1);
expect(result[0].method).to.equal('POST');
expect(result[0].url).to.equal('https://stg-prebid-bidder.adrino.io/bidder/bid/');
expect(result[0].data.bidId).to.equal('12345678901234');
expect(result[0].data.placementHash).to.equal('abcdef123456');
expect(result[0].data.referer).to.equal('http://example.com/');
expect(result[0].data.userAgent).to.equal(navigator.userAgent);
expect(result[0].data).to.have.property('nativeParams');
expect(result[0].data).not.to.have.property('gdprConsent');
expect(result[0].data).to.have.property('userId');
expect(result[0].data.userId.criteoId).to.equal('2xqi3F94aHdwWnM3');
expect(result[0].data.userId.pubcid).to.equal('3ec0b202-7697');
expect(result[0].url).to.equal('https://stg-prebid-bidder.adrino.io/bidder/bids/');
expect(result[0].data[0].bidId).to.equal('12345678901234');
expect(result[0].data[0].placementHash).to.equal('abcdef123456');
expect(result[0].data[0].referer).to.equal('http://example.com/');
expect(result[0].data[0].userAgent).to.equal(navigator.userAgent);
expect(result[0].data[0]).to.have.property('nativeParams');
expect(result[0].data[0]).not.to.have.property('gdprConsent');
expect(result[0].data[0]).to.have.property('userId');
expect(result[0].data[0].userId.criteoId).to.equal('2xqi3F94aHdwWnM3');
expect(result[0].data[0].userId.pubcid).to.equal('3ec0b202-7697');
});

it('should build the request correctly with gdpr', function () {
Expand All @@ -105,16 +105,16 @@ describe('adrinoBidAdapter', function () {
);
expect(result.length).to.equal(1);
expect(result[0].method).to.equal('POST');
expect(result[0].url).to.equal('https://prd-prebid-bidder.adrino.io/bidder/bid/');
expect(result[0].data.bidId).to.equal('12345678901234');
expect(result[0].data.placementHash).to.equal('abcdef123456');
expect(result[0].data.referer).to.equal('http://example.com/');
expect(result[0].data.userAgent).to.equal(navigator.userAgent);
expect(result[0].data).to.have.property('nativeParams');
expect(result[0].data).to.have.property('gdprConsent');
expect(result[0].data).to.have.property('userId');
expect(result[0].data.userId.criteoId).to.equal('2xqi3F94aHdwWnM3');
expect(result[0].data.userId.pubcid).to.equal('3ec0b202-7697');
expect(result[0].url).to.equal('https://prd-prebid-bidder.adrino.io/bidder/bids/');
expect(result[0].data[0].bidId).to.equal('12345678901234');
expect(result[0].data[0].placementHash).to.equal('abcdef123456');
expect(result[0].data[0].referer).to.equal('http://example.com/');
expect(result[0].data[0].userAgent).to.equal(navigator.userAgent);
expect(result[0].data[0]).to.have.property('nativeParams');
expect(result[0].data[0]).to.have.property('gdprConsent');
expect(result[0].data[0]).to.have.property('userId');
expect(result[0].data[0].userId.criteoId).to.equal('2xqi3F94aHdwWnM3');
expect(result[0].data[0].userId.pubcid).to.equal('3ec0b202-7697');
});

it('should build the request correctly without gdpr', function () {
Expand All @@ -124,22 +124,22 @@ describe('adrinoBidAdapter', function () {
);
expect(result.length).to.equal(1);
expect(result[0].method).to.equal('POST');
expect(result[0].url).to.equal('https://prd-prebid-bidder.adrino.io/bidder/bid/');
expect(result[0].data.bidId).to.equal('12345678901234');
expect(result[0].data.placementHash).to.equal('abcdef123456');
expect(result[0].data.referer).to.equal('http://example.com/');
expect(result[0].data.userAgent).to.equal(navigator.userAgent);
expect(result[0].data).to.have.property('nativeParams');
expect(result[0].data).not.to.have.property('gdprConsent');
expect(result[0].data).to.have.property('userId');
expect(result[0].data.userId.criteoId).to.equal('2xqi3F94aHdwWnM3');
expect(result[0].data.userId.pubcid).to.equal('3ec0b202-7697');
expect(result[0].url).to.equal('https://prd-prebid-bidder.adrino.io/bidder/bids/');
expect(result[0].data[0].bidId).to.equal('12345678901234');
expect(result[0].data[0].placementHash).to.equal('abcdef123456');
expect(result[0].data[0].referer).to.equal('http://example.com/');
expect(result[0].data[0].userAgent).to.equal(navigator.userAgent);
expect(result[0].data[0]).to.have.property('nativeParams');
expect(result[0].data[0]).not.to.have.property('gdprConsent');
expect(result[0].data[0]).to.have.property('userId');
expect(result[0].data[0].userId.criteoId).to.equal('2xqi3F94aHdwWnM3');
expect(result[0].data[0].userId.pubcid).to.equal('3ec0b202-7697');
});
});

describe('interpretResponse', function () {
it('should interpret the response correctly', function () {
const response = {
const response1 = {
requestId: '31662c69728811',
mediaType: 'native',
cpm: 0.53,
Expand Down Expand Up @@ -167,13 +167,44 @@ describe('adrinoBidAdapter', function () {
}
};

const response2 = {
requestId: '31662c69728812',
mediaType: 'native',
cpm: 0.77,
currency: 'PLN',
creativeId: '859120',
netRevenue: true,
ttl: 600,
width: 1,
height: 1,
noAd: false,
testAd: false,
native: {
title: 'Ad Title',
body: 'Ad Body',
image: {
url: 'http://emisja.contentstream.pl/_/getImageII/?vid=17180728299&typ=cs_300_150&element=IMAGE&scale=1&prefix=adart&nc=1643878278955',
height: 150,
width: 300
},
clickUrl: 'http://emisja.contentstream.pl/_/ctr2/?u=https%3A%2F%2Fonline.efortuna.pl%2Fpage%3Fkey%3Dej0xMzUzMTM1NiZsPTE1Mjc1MzY1JnA9NTMyOTA%253D&e=znU3tABN8K4N391dmUxYfte5G9tBaDXELJVo1_-kvaTJH2XwWRw77fmfL2YjcEmrbqRQ3M0GcJ0vPWcLtZlsrf8dWrAEHNoZKAC6JMnZF_65IYhTPbQIJ-zn3ac9TU7gEZftFKksH1al7rMuieleVv9r6_DtrOk_oZcYAe4rMRQM-TiWvivJRPBchAAblE0cqyG7rCunJFpal43sxlYm4GvcBJaYHzErn5PXjEzNbd3xHjkdiap-xU9y6BbfkUZ1xIMS8QZLvwNrTXMFCSfSRN2tgVfEj7KyGdLCITHSaFtuIKT2iW2pxC7f2RtPHnzsEPXH0SgAfhA3OxZ5jkQjOZy0PsO7MiCv3sJai5ezUAOjFgayU91ZhI0Y9r2YpB1tTGIjnO23wot8PvRENlThHQ%3D%3D&ref=https%3A%2F%2Fbox.adrino.cloud%2Ftmielcarz%2Fadrino_prebid%2Ftest_page3.html%3Fpbjs_debug%3Dtrue',
privacyLink: 'https://adrino.pl/wp-content/uploads/2021/01/POLITYKA-PRYWATNOS%CC%81CI-Adrino-Mobile.pdf',
impressionTrackers: [
'https://prd-impression-tracker-producer.adrino.io/impression/eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJpbXByZXNzaW9uSWRcIjpcIjMxNjYyYzY5NzI4ODExXCIsXCJkYXRlXCI6WzIwMjIsMiwzXSxcInBsYWNlbWVudEhhc2hcIjpcIjk0NTVjMDQxYzlkMTI1ZmIwNDE4MWVhMGVlZTJmMmFlXCIsXCJjYW1wYWlnbklkXCI6MTc5MjUsXCJhZHZlcnRpc2VtZW50SWRcIjo5MjA3OSxcInZpc3VhbGlzYXRpb25JZFwiOjg1OTExNSxcImNwbVwiOjUzLjB9IiwiZXhwIjoxNjQzOTE2MjUxLCJpYXQiOjE2NDM5MTU2NTF9.0Y_HvInGl6Xo5xP6rDLC8lzQRGvy-wKe0blk1o8ebWyVRFiUY1JGLUeE0k3sCsPNxgdHAv-o6EcbogpUuqlMJA'
]
}
};

const serverResponse = {
body: response
body: { bidResponses: [response1, response2] }
};

const result = spec.interpretResponse(serverResponse, {});
expect(result.length).to.equal(1);
expect(result[0]).to.equal(response);
expect(result.length).to.equal(2);
expect(result[0]).to.equal(response1);
expect(result[0].requestId).to.equal('31662c69728811');
expect(result[1]).to.equal(response2);
expect(result[1].requestId).to.equal('31662c69728812');
});

it('should return empty array of responses', function () {
Expand Down

0 comments on commit 2a926e1

Please sign in to comment.