Skip to content

Commit

Permalink
Alkimi Bid Adapter : add multisize multiformat (prebid#9575)
Browse files Browse the repository at this point in the history
* 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

* ALK-504
Multi size ad slot support

* ALK-504
Multi size ad slot support

---------

Co-authored-by: Alexander <32703851+pro-nsk@users.noreply.github.com>
Co-authored-by: Alexander Bogdanov <akascheev@asteriosoft.com>
Co-authored-by: Alexander Bogdanov <abogdanov@asteriosoft.com>
Co-authored-by: motors <motors@live.ru>
Co-authored-by: Kalidas Engaiahraj <kalidas@alkimiexchange.com>
Co-authored-by: mik <mihanikw2g@gmail.com>
  • Loading branch information
7 people authored and jorgeluisrocha committed May 18, 2023
1 parent b344df4 commit ffa4b77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
59 changes: 32 additions & 27 deletions modules/alkimiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { deepClone, deepAccess } from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import { VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {deepClone, deepAccess} from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import {VIDEO} from '../src/mediaTypes.js';
import {config} from '../src/config.js';

const BIDDER_CODE = 'alkimi';
export const ENDPOINT = 'https://exchange.alkimi-onboarding.com/bid?prebid=true';
Expand All @@ -20,8 +20,7 @@ export const spec = {
let bidIds = [];
let eids;
validBidRequests.forEach(bidRequest => {
let formatType = getFormatType(bidRequest)
let alkimiSizes = prepareAlkimiSizes(bidRequest.sizes)
let formatTypes = getFormatType(bidRequest)

if (bidRequest.userIdAsEids) {
eids = eids || bidRequest.userIdAsEids
Expand All @@ -30,10 +29,10 @@ export const spec = {
bids.push({
token: bidRequest.params.token,
pos: bidRequest.params.pos,
bidFloor: getBidFloor(bidRequest, formatType),
width: alkimiSizes[0].width,
height: alkimiSizes[0].height,
impMediaType: formatType,
bidFloor: getBidFloor(bidRequest, formatTypes),
sizes: prepareSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes')),
playerSizes: prepareSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize')),
impMediaTypes: formatTypes,
adUnitCode: bidRequest.adUnitCode
})
bidIds.push(bidRequest.bidId)
Expand All @@ -43,7 +42,7 @@ export const spec = {

let payload = {
requestId: bidderRequest.auctionId,
signRequest: { bids, randomUUID: alkimiConfig && alkimiConfig.randomUUID },
signRequest: {bids, randomUUID: alkimiConfig && alkimiConfig.randomUUID},
bidIds,
referer: bidderRequest.refererInfo.page,
signature: alkimiConfig && alkimiConfig.signature,
Expand Down Expand Up @@ -87,7 +86,7 @@ export const spec = {
return [];
}

const { prebidResponse } = serverBody;
const {prebidResponse} = serverBody;
if (!prebidResponse || typeof prebidResponse !== 'object') {
return [];
}
Expand Down Expand Up @@ -115,7 +114,7 @@ export const spec = {
let winUrl;
if (bid.winUrl || bid.vastUrl) {
winUrl = bid.winUrl ? bid.winUrl : bid.vastUrl;
winUrl = winUrl.replace(/\$\{AUCTION_PRICE\}/, bid.cpm);
winUrl = winUrl.replace(/\$\{AUCTION_PRICE}/, bid.cpm);
} else if (bid.ad) {
let trackImg = bid.ad.match(/(?!^)<img src=".+dsp-win.+">/);
bid.ad = bid.ad.replace(trackImg[0], '');
Expand All @@ -130,29 +129,35 @@ export const spec = {
}
}

function prepareAlkimiSizes(sizes) {
return sizes && sizes.map(size => ({ width: size[0], height: size[1] }));
function prepareSizes(sizes) {
return sizes ? sizes.map(size => ({width: size[0], height: size[1]})) : []
}

function prepareBidFloorSize(sizes) {
return sizes && sizes.length === 1 ? sizes[0] : '*';
return sizes && sizes.length === 1 ? sizes : ['*'];
}

function getBidFloor(bidRequest, formatType) {
function getBidFloor(bidRequest, formatTypes) {
let minFloor
if (typeof bidRequest.getFloor === 'function') {
const bidFloorSize = prepareBidFloorSize(bidRequest.sizes)
const floor = bidRequest.getFloor({ currency: 'USD', mediaType: formatType.toLowerCase(), size: bidFloorSize });
if (floor && !isNaN(floor.floor) && (floor.currency === 'USD')) {
return floor.floor;
}
const bidFloorSizes = prepareBidFloorSize(bidRequest.sizes)
formatTypes.forEach(formatType => {
bidFloorSizes.forEach(bidFloorSize => {
const floor = bidRequest.getFloor({currency: 'USD', mediaType: formatType.toLowerCase(), size: bidFloorSize});
if (floor && !isNaN(floor.floor) && (floor.currency === 'USD')) {
minFloor = !minFloor || floor.floor < minFloor ? floor.floor : minFloor
}
})
})
}
return bidRequest.params.bidFloor;
return minFloor || bidRequest.params.bidFloor;
}

const getFormatType = bidRequest => {
if (deepAccess(bidRequest, 'mediaTypes.banner')) return 'Banner'
if (deepAccess(bidRequest, 'mediaTypes.video')) return 'Video'
if (deepAccess(bidRequest, 'mediaTypes.audio')) return 'Audio'
let formats = []
if (deepAccess(bidRequest, 'mediaTypes.banner')) formats.push('Banner')
if (deepAccess(bidRequest, 'mediaTypes.video')) formats.push('Video')
return formats
}

registerBidder(spec);
2 changes: 1 addition & 1 deletion test/spec/modules/alkimiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('alkimiBidAdapter', function () {
expect(bidderRequest.data.requestId).to.equal('123')
expect(bidderRequest.data.referer).to.equal('http://test.com/path.html')
expect(bidderRequest.data.schain).to.deep.contains({ ver: '1.0', complete: 1, nodes: [{ asi: 'alkimi-onboarding.com', sid: '00001', hp: 1 }] })
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' })
expect(bidderRequest.data.signRequest.bids).to.deep.contains({ token: 'e64782a4-8e68-4c38-965b-80ccf115d46f', pos: 7, bidFloor: 0.1, sizes: [{width: 300, height: 250}], playerSizes: [], impMediaTypes: ['Banner'], adUnitCode: 'bannerAdUnitCode' })
expect(bidderRequest.data.signRequest.randomUUID).to.equal(undefined)
expect(bidderRequest.data.bidIds).to.deep.contains('456')
expect(bidderRequest.data.signature).to.equal(undefined)
Expand Down

0 comments on commit ffa4b77

Please sign in to comment.