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

Datawrkz adapter: Using bidRequest.getFloor() method for bid floor #9366

Merged
merged 5 commits into from
Dec 26, 2022
Merged
Changes from all commits
Commits
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
28 changes: 24 additions & 4 deletions modules/datawrkzBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepAccess, getBidIdParameter, isArray, getUniqueIdentifierStr, contains } from '../src/utils.js';
import { deepAccess, getBidIdParameter, isArray, getUniqueIdentifierStr, contains, isFn, isPlainObject } from '../src/utils.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
Expand Down Expand Up @@ -84,7 +84,7 @@ export const spec = {

/* Generate bid request for banner adunit */
function buildBannerRequest(bidRequest, bidderRequest) {
let bidFloor = Number(getBidIdParameter('bidfloor', bidRequest.params));
let bidFloor = getBidFloor(bidRequest);

let adW = 0;
let adH = 0;
Expand Down Expand Up @@ -135,7 +135,7 @@ function buildNativeRequest(bidRequest, bidderRequest) {
let counter = 0;
let assets = [];

let bidFloor = Number(getBidIdParameter('bidfloor', bidRequest.params));
let bidFloor = getBidFloor(bidRequest);

let title = deepAccess(bidRequest, 'mediaTypes.native.title');
if (title && title.len) {
Expand Down Expand Up @@ -196,7 +196,7 @@ function buildNativeRequest(bidRequest, bidderRequest) {

/* Generate bid request for video adunit */
function buildVideoRequest(bidRequest, bidderRequest) {
let bidFloor = Number(getBidIdParameter('bidfloor', bidRequest.params));
let bidFloor = getBidFloor(bidRequest);

let sizeObj = getVideoAdUnitSize(bidRequest);

Expand Down Expand Up @@ -414,6 +414,7 @@ function buildBannerResponse(bidRequest, bidResponse) {
}
let bidSizes = (deepAccess(bidRequest, 'mediaTypes.banner.sizes')) ? deepAccess(bidRequest, 'mediaTypes.banner.sizes') : bidRequest.sizes;
bidResponse.requestId = bidRequest.bidId;
bidResponse.auctionId = bidRequest.auctionId;
bidResponse.transactionId = bidRequest.transactionId;
bidResponse.placementCode = placementCode;
bidResponse.cpm = responseCPM;
Expand Down Expand Up @@ -455,6 +456,7 @@ function buildNativeResponse(bidRequest, response) {
return;
}
bidResponse.requestId = bidRequest.bidId;
bidResponse.auctionId = bidRequest.auctionId;
bidResponse.transactionId = bidRequest.transactionId;
bidResponse.placementCode = placementCode;
bidResponse.cpm = responseCPM;
Expand Down Expand Up @@ -507,6 +509,7 @@ function buildVideoResponse(bidRequest, response) {
let context = bidRequest.mediaTypes.video.context;

bidResponse.requestId = bidRequest.bidId;
bidResponse.auctionId = bidRequest.auctionId;
bidResponse.transactionId = bidRequest.transactionId;
bidResponse.placementCode = placementCode;
bidResponse.cpm = responseCPM;
Expand Down Expand Up @@ -630,4 +633,21 @@ function getNativeAssestObj(obj, assets) {
}
}

// BUILD REQUESTS: BIDFLOORS
function getBidFloor(bid) {
if (!isFn(bid.getFloor)) {
return (bid.params.bidfloor) ? bid.params.bidfloor : null;
}

let floor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*'
});
if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') {
return floor.floor;
}
return null;
}

registerBidder(spec);