Skip to content

Commit

Permalink
Eplanning Bid Adapter: add support for video (prebid#9044)
Browse files Browse the repository at this point in the history
* add video

* move up imptypes logic

* fix linting

* update curly braces

* fix spaces linting

* fix line
  • Loading branch information
ChrisHuie authored and JacobKlein26 committed Feb 8, 2023
1 parent 254e896 commit 5803ce9
Show file tree
Hide file tree
Showing 2 changed files with 333 additions and 3 deletions.
50 changes: 48 additions & 2 deletions modules/eplanningBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {getWindowSelf, isEmpty, parseSizesInput, isGptPubadsDefined, isSlotMatch
import {getGlobal} from '../src/prebidGlobal.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getStorageManager} from '../src/storageManager.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';

const BIDDER_CODE = 'eplanning';
export const storage = getStorageManager({bidderCode: BIDDER_CODE});
Expand All @@ -19,9 +20,14 @@ const STORAGE_VIEW_PREFIX = 'pbvi_';
const mobileUserAgent = isMobileUserAgent();
const PRIORITY_ORDER_FOR_MOBILE_SIZES_ASC = ['1x1', '300x50', '320x50', '300x250'];
const PRIORITY_ORDER_FOR_DESKTOP_SIZES_ASC = ['1x1', '970x90', '970x250', '160x600', '300x600', '728x90', '300x250'];
const VAST_INSTREAM = 1;
const VAST_OUTSTREAM = 2;
const VAST_VERSION_DEFAULT = 3;
const DEFAULT_SIZE_VAST = '640x480';

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

isBidRequestValid: function(bid) {
return Boolean(bid.params.ci) || Boolean(bid.params.t);
Expand Down Expand Up @@ -86,6 +92,10 @@ export const spec = {
params['e_' + id] = (typeof userIds[id] === 'object') ? encodeURIComponent(JSON.stringify(userIds[id])) : encodeURIComponent(userIds[id]);
}
}
if (spaces.impType) {
params.vctx = spaces.impType & VAST_INSTREAM ? VAST_INSTREAM : VAST_OUTSTREAM;
params.vv = VAST_VERSION_DEFAULT;
}
}

return {
Expand All @@ -108,7 +118,6 @@ export const spec = {
cpm: ad.pr,
width: ad.w,
height: ad.h,
ad: ad.adm,
ttl: TTL,
creativeId: ad.crid,
netRevenue: NET_REVENUE,
Expand All @@ -119,6 +128,13 @@ export const spec = {
advertiserDomains: ad.adom
};
}
if (isVastResponse(ad)) {
bidResponse.vastXml = ad.adm;
bidResponse.mediaTypes = VIDEO;
} else {
bidResponse.ad = ad.adm;
}

bidResponses.push(bidResponse);
});
}
Expand Down Expand Up @@ -236,17 +252,42 @@ function getSpacesStruct(bids) {
return e;
}

function getFirstSizeVast(sizes) {
if (sizes == undefined || !Array.isArray(sizes)) {
return undefined;
}

let size = Array.isArray(sizes[0]) ? sizes[0] : sizes;

return (Array.isArray(size) && size.length == 2) ? size : undefined;
}

function cleanName(name) {
return name.replace(/_|\.|-|\//g, '').replace(/\)\(|\(|\)|:/g, '_').replace(/^_+|_+$/g, '');
}

function getSpaces(bidRequests, ml) {
let impType = bidRequests.reduce((previousBits, bid) => (bid.mediaTypes && bid.mediaTypes[VIDEO]) ? (bid.mediaTypes[VIDEO].context == 'outstream' ? (previousBits | 2) : (previousBits | 1)) : previousBits, 0);
// Only one type of auction is supported at a time
if (impType) {
bidRequests = bidRequests.filter((bid) => bid.mediaTypes && bid.mediaTypes[VIDEO] && (impType & VAST_INSTREAM ? (!bid.mediaTypes[VIDEO].context || bid.mediaTypes[VIDEO].context == 'instream') : (bid.mediaTypes[VIDEO].context == 'outstream')));
}

let spacesStruct = getSpacesStruct(bidRequests);
let es = {str: '', vs: '', map: {}};
let es = {str: '', vs: '', map: {}, impType: impType};
es.str = Object.keys(spacesStruct).map(size => spacesStruct[size].map((bid, i) => {
es.vs += getVs(bid);

let name;

if (impType) {
let firstSize = getFirstSizeVast(bid.mediaTypes[VIDEO].playerSize);
let sizeVast = firstSize ? firstSize.join('x') : DEFAULT_SIZE_VAST;
name = 'video_' + sizeVast + '_' + i;
es.map[name] = bid.bidId;
return name + ':' + sizeVast + ';1';
}

if (ml) {
name = cleanName(bid.adUnitCode);
} else {
Expand Down Expand Up @@ -462,4 +503,9 @@ function registerAuction(storageID) {

return true;
}

function isVastResponse(bid) {
return bid.adm.match(/^(<VAST)|(<VideoAdServingTemplate)/gmi);
}

registerBidder(spec);
Loading

0 comments on commit 5803ce9

Please sign in to comment.