Skip to content

Commit

Permalink
Update admaticBidAdapter.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihkaya84 committed Oct 31, 2022
1 parent 7a23b05 commit 7a845b7
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion modules/admaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getValue, logError, deepAccess, getBidIdParameter, isArray } from '../src/utils.js';
import { loadExternalScript } from '../src/adloader.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const ENDPOINT_URL = 'https://layer.serve.admatic.com.tr/pb';
const SYNC_URL = 'https://cdn.serve.admatic.com.tr/showad/sync.js';
Expand Down Expand Up @@ -100,17 +101,66 @@ export const spec = {
timeToRespond: 1,
requestTimestamp: 1
};

bidResponses.push(resbid);
});
};
return bidResponses;
}
};

function enrichSlotWithFloors(slot, bidRequest) {
try {
const slotFloors = {};

if (bidRequest.getFloor) {
if (bidRequest.mediaTypes?.banner) {
slotFloors.banner = {};
const bannerSizes = parseSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes'))
bannerSizes.forEach(bannerSize => slotFloors.banner[parseSize(bannerSize).toString()] = bidRequest.getFloor({ size: bannerSize, mediaType: BANNER }));
}

if (bidRequest.mediaTypes?.video) {
slotFloors.video = {};
const videoSizes = parseSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize'))
videoSizes.forEach(videoSize => slotFloors.video[parseSize(videoSize).toString()] = bidRequest.getFloor({ size: videoSize, mediaType: VIDEO }));
}

if (Object.keys(slotFloors).length > 0) {
if (!slot) {
slot = {}
}
Object.assign(slot, {
floors: slotFloors
});
}
}
} catch (e) {
logError('Could not parse floors from Prebid: ' + e);
}
}

function parseSizes(sizes, parser = s => s) {
if (sizes == undefined) {
return [];
}
if (Array.isArray(sizes[0])) { // is there several sizes ? (ie. [[728,90],[200,300]])
return sizes.map(size => parser(size));
}
return [parser(sizes)]; // or a single one ? (ie. [728,90])
}

function parseSize(size) {
return size[0] + 'x' + size[1];
}

function buildRequestObject(bid) {
const reqObj = {};
reqObj.size = getSizes(bid);
reqObj.id = getBidIdParameter('bidId', bid);

enrichSlotWithFloors(reqObj, bid);

return reqObj;
}

Expand Down

0 comments on commit 7a845b7

Please sign in to comment.