Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alkimi Bid Adapter : add multisize multiformat #9575

Merged
merged 27 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
10ae6ca
Merge pull request #1 from prebid/master
pro-nsk Nov 15, 2021
325c162
Alkimi bid adapter
Nov 15, 2021
df09e0d
Alkimi bid adapter
pro-nsk Nov 17, 2021
b3e3688
Alkimi bid adapter
pro-nsk Nov 17, 2021
144cda7
alkimi adapter
pro-nsk Feb 7, 2022
c14dcd2
onBidWon change
pro-nsk Feb 8, 2022
ddec997
sign utils
pro-nsk Feb 8, 2022
068c546
auction ID as bid request ID
pro-nsk Feb 24, 2022
df2d98b
Merge pull request #2 from prebid/master
pro-nsk Apr 26, 2022
bf432c4
unit test fixes
pro-nsk Apr 27, 2022
76afe9b
change maintainer info
pro-nsk May 11, 2022
2e6c2ac
Merge branch 'master' into master
pro-nsk May 11, 2022
7dc389d
Updated the ad unit params
kalidas-alkimi May 16, 2022
74a85e4
Merge remote-tracking branch 'upstream/master'
kalidas-alkimi May 17, 2022
b6a9dc4
Merge pull request #4 from prebid/master
pro-nsk May 31, 2022
8675d2a
Merge pull request #5 from prebid/master
mihanikw2g May 31, 2022
ea2a9bf
features support added
mihanikw2g May 31, 2022
53e1ecc
Merge branch 'master' into master
pro-nsk Jun 16, 2022
011053e
Merge pull request #7 from prebid/master
pro-nsk Aug 24, 2022
74f8e12
transfer adUnitCode
pro-nsk Aug 24, 2022
0a0d8e8
transfer adUnitCode: test
pro-nsk Aug 24, 2022
afb97d8
Merge pull request #9 from prebid/master
pro-nsk Dec 21, 2022
41b6ca3
AlkimiBidAdapter getFloor() using
pro-nsk Dec 22, 2022
cabf081
Merge pull request #11 from prebid/master
pro-nsk Feb 7, 2023
dfcf4e8
ALK-504
mw2g Feb 8, 2023
1a9fe87
ALK-504
mw2g Feb 13, 2023
8a867e9
Merge pull request #12 from prebid/master
mihanikw2g Feb 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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