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

Eplanning Bid Adapter: add support for video #9044

Merged
merged 6 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
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
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required, but for better readability, would you want to replace the part
bid.mediaTypes[VIDEO].context == 'outstream' ? (previousBits | 2) : (previousBits | 1)

by

bid.mediaTypes[VIDEO].context == 'outstream' ? (previousBits | VAST_OUTSTREAM) : (previousBits | VAST_INSTREAM)

// 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