Skip to content

Commit

Permalink
size map support (prebid#9772)
Browse files Browse the repository at this point in the history
  • Loading branch information
0tarof authored and jorgeluisrocha committed May 18, 2023
1 parent 2a926e1 commit d7b11d9
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions modules/ajaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@ import { getBidIdParameter, tryAppendQueryString, createTrackPixelHtml, logError
import { Renderer } from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';

const BIDDER_CODE = 'aja';
const BidderCode = 'aja';
const URL = 'https://ad.as.amanad.adtdp.com/v2/prebid';
const SDK_TYPE = 5;
const AD_TYPE = {
BANNER: 1,
NATIVE: 2,
VIDEO: 3,
const SDKType = 5;
const AdType = {
Banner: 1,
Native: 2,
Video: 3,
};

const BannerSizeMap = {
'970x250': 1,
'300x250': 2,
'320x50': 3,
'728x90': 4,
'320x100': 6,
'336x280': 31,
'300x600': 32,
}

export const spec = {
code: BIDDER_CODE,
code: BidderCode,
supportedMediaTypes: [VIDEO, BANNER, NATIVE],

/**
Expand All @@ -36,9 +45,6 @@ export const spec = {
* @returns {ServerRequest|ServerRequest[]}
*/
buildRequests: function(validBidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);

const bidRequests = [];
const pageUrl = bidderRequest?.refererInfo?.page || undefined;

Expand All @@ -48,7 +54,7 @@ export const spec = {

const asi = getBidIdParameter('asi', bidRequest.params);
queryString = tryAppendQueryString(queryString, 'asi', asi);
queryString = tryAppendQueryString(queryString, 'skt', SDK_TYPE);
queryString = tryAppendQueryString(queryString, 'skt', SDKType);
queryString = tryAppendQueryString(queryString, 'tid', bidRequest.transactionId)
queryString = tryAppendQueryString(queryString, 'prebid_id', bidRequest.bidId);
queryString = tryAppendQueryString(queryString, 'prebid_ver', '$prebid.version$');
Expand All @@ -57,11 +63,27 @@ export const spec = {
queryString = tryAppendQueryString(queryString, 'page_url', pageUrl);
}

const banner = deepAccess(bidRequest, `mediaTypes.${BANNER}`)
if (banner) {
const adFormatIDs = [];
for (const size of banner.sizes || []) {
if (size.length !== 2) {
continue
}

const adFormatID = BannerSizeMap[`${size[0]}x${size[1]}`];
if (adFormatID) {
adFormatIDs.push(adFormatID);
}
}
queryString = tryAppendQueryString(queryString, 'ad_format_ids', adFormatIDs.join(','));
}

const eids = bidRequest.userIdAsEids;
if (eids && eids.length) {
queryString = tryAppendQueryString(queryString, 'eids', JSON.stringify({
'eids': eids,
}))
}));
}

const sua = deepAccess(bidRequest, 'ortb2.device.sua');
Expand Down Expand Up @@ -101,7 +123,7 @@ export const spec = {
},
}

if (AD_TYPE.VIDEO === ad.ad_type) {
if (AdType.Video === ad.ad_type) {
const videoAd = bidderResponseBody.ad.video;
Object.assign(bid, {
vastXml: videoAd.vtag,
Expand All @@ -113,7 +135,7 @@ export const spec = {
});

Array.prototype.push.apply(bid.meta.advertiserDomains, videoAd.adomain)
} else if (AD_TYPE.BANNER === ad.ad_type) {
} else if (AdType.Banner === ad.ad_type) {
const bannerAd = bidderResponseBody.ad.banner;
Object.assign(bid, {
width: bannerAd.w,
Expand All @@ -131,7 +153,7 @@ export const spec = {
}

Array.prototype.push.apply(bid.meta.advertiserDomains, bannerAd.adomain)
} else if (AD_TYPE.NATIVE === ad.ad_type) {
} else if (AdType.Native === ad.ad_type) {
const nativeAds = ad.native.template_and_ads.ads;
if (nativeAds.length === 0) {
return [];
Expand Down

0 comments on commit d7b11d9

Please sign in to comment.