Skip to content

Commit f7c9e05

Browse files
pro-nskAlexander Bogdanovkalidas-alkimimihanikw2g
authored andcommitted
Alkimi Bid Adapter: using the floors convention (prebid#9368)
* Alkimi bid adapter * Alkimi bid adapter * Alkimi bid adapter * alkimi adapter * onBidWon change * sign utils * auction ID as bid request ID * unit test fixes * change maintainer info * Updated the ad unit params * features support added * transfer adUnitCode * transfer adUnitCode: test * AlkimiBidAdapter getFloor() using Co-authored-by: Alexander Bogdanov <[email protected]> Co-authored-by: Kalidas Engaiahraj <[email protected]> Co-authored-by: mihanikw2g <[email protected]> Co-authored-by: Nikulin Mikhail <[email protected]>
1 parent 5858ae0 commit f7c9e05

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

modules/alkimiBidAdapter.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ export const spec = {
2020
let bidIds = [];
2121
let eids;
2222
validBidRequests.forEach(bidRequest => {
23-
let sizes = prepareSizes(bidRequest.sizes)
23+
let formatType = getFormatType(bidRequest)
24+
let alkimiSizes = prepareAlkimiSizes(bidRequest.sizes)
2425

2526
if (bidRequest.userIdAsEids) {
2627
eids = eids || bidRequest.userIdAsEids
2728
}
29+
2830
bids.push({
2931
token: bidRequest.params.token,
3032
pos: bidRequest.params.pos,
31-
bidFloor: bidRequest.params.bidFloor,
32-
width: sizes[0].width,
33-
height: sizes[0].height,
34-
impMediaType: getFormatType(bidRequest),
33+
bidFloor: getBidFloor(bidRequest, formatType),
34+
width: alkimiSizes[0].width,
35+
height: alkimiSizes[0].height,
36+
impMediaType: formatType,
3537
adUnitCode: bidRequest.adUnitCode
3638
})
3739
bidIds.push(bidRequest.bidId)
@@ -128,10 +130,25 @@ export const spec = {
128130
}
129131
}
130132

131-
function prepareSizes(sizes) {
133+
function prepareAlkimiSizes(sizes) {
132134
return sizes && sizes.map(size => ({ width: size[0], height: size[1] }));
133135
}
134136

137+
function prepareBidFloorSize(sizes) {
138+
return sizes && sizes.length === 1 ? sizes[0] : '*';
139+
}
140+
141+
function getBidFloor(bidRequest, formatType) {
142+
if (typeof bidRequest.getFloor === 'function') {
143+
const bidFloorSize = prepareBidFloorSize(bidRequest.sizes)
144+
const floor = bidRequest.getFloor({ currency: 'USD', mediaType: formatType.toLowerCase(), size: bidFloorSize });
145+
if (floor && !isNaN(floor.floor) && (floor.currency === 'USD')) {
146+
return floor.floor;
147+
}
148+
}
149+
return bidRequest.params.bidFloor;
150+
}
151+
135152
const getFormatType = bidRequest => {
136153
if (deepAccess(bidRequest, 'mediaTypes.banner')) return 'Banner'
137154
if (deepAccess(bidRequest, 'mediaTypes.video')) return 'Video'

test/spec/modules/alkimiBidAdapter_spec.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('alkimiBidAdapter', function () {
108108

109109
describe('buildRequests', function () {
110110
let bidRequests = [REQUEST]
111-
const bidderRequest = spec.buildRequests(bidRequests, {
111+
let requestData = {
112112
auctionId: '123',
113113
refererInfo: {
114114
page: 'http://test.com/path.html'
@@ -119,7 +119,8 @@ describe('alkimiBidAdapter', function () {
119119
gdprApplies: true
120120
},
121121
uspConsent: 'uspConsent'
122-
})
122+
}
123+
const bidderRequest = spec.buildRequests(bidRequests, requestData)
123124

124125
it('should return a properly formatted request with eids defined', function () {
125126
expect(bidderRequest.data.eids).to.deep.equal(REQUEST.userIdAsEids)
@@ -138,7 +139,7 @@ describe('alkimiBidAdapter', function () {
138139
expect(bidderRequest.method).to.equal('POST')
139140
expect(bidderRequest.data.requestId).to.equal('123')
140141
expect(bidderRequest.data.referer).to.equal('http://test.com/path.html')
141-
expect(bidderRequest.data.schain).to.deep.contains({ver: '1.0', complete: 1, nodes: [{asi: 'alkimi-onboarding.com', sid: '00001', hp: 1}]})
142+
expect(bidderRequest.data.schain).to.deep.contains({ ver: '1.0', complete: 1, nodes: [{ asi: 'alkimi-onboarding.com', sid: '00001', hp: 1 }] })
142143
expect(bidderRequest.data.signRequest.bids).to.deep.contains({ token: 'e64782a4-8e68-4c38-965b-80ccf115d46f', pos: 7, bidFloor: 0.1, width: 300, height: 250, impMediaType: 'Banner', adUnitCode: 'bannerAdUnitCode' })
143144
expect(bidderRequest.data.signRequest.randomUUID).to.equal(undefined)
144145
expect(bidderRequest.data.bidIds).to.deep.contains('456')
@@ -147,6 +148,17 @@ describe('alkimiBidAdapter', function () {
147148
expect(bidderRequest.options.contentType).to.equal('application/json')
148149
expect(bidderRequest.url).to.equal(ENDPOINT)
149150
})
151+
152+
it('sends bidFloor when configured', () => {
153+
const requestWithFloor = Object.assign({}, REQUEST);
154+
requestWithFloor.getFloor = function (arg) {
155+
if (arg.currency === 'USD' && arg.mediaType === 'banner' && JSON.stringify(arg.size) === JSON.stringify([300, 250])) {
156+
return { currency: 'USD', floor: 0.3 }
157+
}
158+
}
159+
const bidderRequestFloor = spec.buildRequests([requestWithFloor], requestData);
160+
expect(bidderRequestFloor.data.signRequest.bids[0].bidFloor).to.be.equal(0.3);
161+
});
150162
})
151163

152164
describe('interpretResponse', function () {

0 commit comments

Comments
 (0)