Skip to content

Commit

Permalink
Merge pull request #16 from smartadserver/floor-per-mediatype
Browse files Browse the repository at this point in the history
Rework payloads enriching
  • Loading branch information
krzysztofequativ authored Jan 25, 2023
2 parents 18c659b + 5b89a6e commit 6db82d2
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,28 @@ export const spec = {
payload.us_privacy = bidderRequest.uspConsent;
}

const videoMediaType = deepAccess(bid, 'mediaTypes.video');
const bannerMediaType = deepAccess(bid, 'mediaTypes.banner');
const isAdUnitContainingVideo = videoMediaType && (videoMediaType.context === 'instream' || videoMediaType.context === 'outstream');

if (!isAdUnitContainingVideo && bannerMediaType) {
payload.sizes = spec.adaptBannerSizes(bannerMediaType.sizes);
payload.bidfloor = bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency, BANNER);
bidRequests.push(spec.createServerRequest(payload, bid.params.domain));
} else if (isAdUnitContainingVideo && !bannerMediaType) {
spec.fillPayloadForVideoBidRequest(payload, videoMediaType, bid.params.video);
payload.bidfloor = bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency, VIDEO);
bidRequests.push(spec.createServerRequest(payload, bid.params.domain));
} else if (isAdUnitContainingVideo && bannerMediaType) {
// If there are video and banner media types in the ad unit, we clone the payload
// to create a specific one for video.
let videoPayload = deepClone(payload);
const videoMediaType = deepAccess(bid, 'mediaTypes.video');
const isSupportedVideoContext = videoMediaType && (videoMediaType.context === 'instream' || videoMediaType.context === 'outstream');

spec.fillPayloadForVideoBidRequest(videoPayload, videoMediaType, bid.params.video);
videoPayload.bidfloor = bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency, VIDEO);
bidRequests.push(spec.createServerRequest(videoPayload, bid.params.domain));
if (bannerMediaType || isSupportedVideoContext) {
let type;
if (bannerMediaType) {
type = BANNER;
payload.sizes = spec.adaptBannerSizes(bannerMediaType.sizes);

payload.sizes = spec.adaptBannerSizes(bannerMediaType.sizes);
payload.bidfloor = bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency, BANNER);
if (isSupportedVideoContext) {
let videoPayload = deepClone(payload);
spec.fillPayloadForVideoBidRequest(videoPayload, videoMediaType, bid.params.video);
videoPayload.bidfloor = bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency, VIDEO);
bidRequests.push(spec.createServerRequest(videoPayload, bid.params.domain));
}
} else {
type = VIDEO;
spec.fillPayloadForVideoBidRequest(payload, videoMediaType, bid.params.video);
}

payload.bidfloor = bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency, type);
bidRequests.push(spec.createServerRequest(payload, bid.params.domain));
} else {
bidRequests.push({});
Expand Down

0 comments on commit 6db82d2

Please sign in to comment.