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

Add banner support to Beachfront adapter #2117

Merged
merged 20 commits into from
Mar 6, 2018
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
187 changes: 147 additions & 40 deletions modules/beachfrontBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,196 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { VIDEO, BANNER } from 'src/mediaTypes';
import find from 'core-js/library/fn/array/find';

export const ENDPOINT = '//reachms.bfmio.com/bid.json?exchange_id=';
const ADAPTER_VERSION = '1.0';
const ADAPTER_NAME = 'BFIO_PREBID';

export const VIDEO_ENDPOINT = '//reachms.bfmio.com/bid.json?exchange_id=';
export const BANNER_ENDPOINT = '//display.bfmio.com/prebid_display';

export const spec = {
code: 'beachfront',
supportedMediaTypes: ['video'],
supportedMediaTypes: [ VIDEO, BANNER ],

isBidRequestValid(bid) {
return !!(bid && bid.params && bid.params.appId && bid.params.bidfloor);
},

buildRequests(bids) {
return bids.map(bid => {
return {
let requests = [];
let videoBids = bids.filter(bid => isVideoBid(bid));
let bannerBids = bids.filter(bid => !isVideoBid(bid));
videoBids.forEach(bid => {
requests.push({
method: 'POST',
url: ENDPOINT + bid.params.appId,
data: createRequestParams(bid),
url: VIDEO_ENDPOINT + bid.params.appId,
data: createVideoRequestData(bid),
bidRequest: bid
};
});
});
if (bannerBids.length) {
requests.push({
method: 'POST',
url: BANNER_ENDPOINT,
data: createBannerRequestData(bannerBids),
bidRequest: bannerBids
});
}
return requests;
},

interpretResponse(response, { bidRequest }) {
response = response.body;
if (!response || !response.url || !response.bidPrice) {
utils.logWarn(`No valid bids from ${spec.code} bidder`);
return [];

if (isVideoBid(bidRequest)) {
if (!response || !response.url || !response.bidPrice) {
utils.logWarn(`No valid video bids from ${spec.code} bidder`);
return [];
}
let size = getFirstSize(bidRequest);
return {
requestId: bidRequest.bidId,
bidderCode: spec.code,
vastUrl: response.url,
cpm: response.bidPrice,
width: size.w,
height: size.h,
creativeId: response.cmpId,
mediaType: VIDEO,
currency: 'USD',
netRevenue: true,
ttl: 300
};
} else {
if (!response || !response.length) {
utils.logWarn(`No valid banner bids from ${spec.code} bidder`);
return [];
}
return response.map((bid) => {
let request = find(bidRequest, req => req.adUnitCode === bid.slot);
return {
requestId: request.bidId,
bidderCode: spec.code,
ad: bid.adm,
creativeId: bid.crid,
cpm: bid.price,
width: bid.w,
height: bid.h,
mediaType: BANNER,
currency: 'USD',
netRevenue: true,
ttl: 300
};
});
}
let size = getSize(bidRequest.sizes);
return {
requestId: bidRequest.bidId,
bidderCode: spec.code,
cpm: response.bidPrice,
creativeId: response.cmpId,
vastUrl: response.url,
width: size.width,
height: size.height,
mediaType: 'video',
currency: 'USD',
ttl: 300,
netRevenue: true
};
}
};

function getSize(sizes) {
let parsedSizes = utils.parseSizesInput(sizes);
let [ width, height ] = parsedSizes.length ? parsedSizes[0].split('x') : [];
return {
width: parseInt(width, 10) || undefined,
height: parseInt(height, 10) || undefined
};
function getSizes(bid) {
return utils.parseSizesInput(bid.sizes).map(size => {
let [ width, height ] = size.split('x');
return {
w: parseInt(width, 10) || undefined,
h: parseInt(height, 10) || undefined
};
});
}

function getFirstSize(bid) {
let sizes = getSizes(bid);
return sizes.length ? sizes[0] : { w: undefined, h: undefined };
}

function getOsVersion() {
let clientStrings = [
{ s: 'Android', r: /Android/ },
{ s: 'iOS', r: /(iPhone|iPad|iPod)/ },
{ s: 'Mac OS X', r: /Mac OS X/ },
{ s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
{ s: 'Linux', r: /(Linux|X11)/ },
{ s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ },
{ s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ },
{ s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ },
{ s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ },
{ s: 'Windows Vista', r: /Windows NT 6.0/ },
{ s: 'Windows Server 2003', r: /Windows NT 5.2/ },
{ s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ },
{ s: 'UNIX', r: /UNIX/ },
{ s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ }
];
let cs = find(clientStrings, cs => cs.r.test(navigator.userAgent));
return cs ? cs.s : 'unknown';
}

function isMobile() {
return (/(ios|ipod|ipad|iphone|android)/i).test(global.navigator.userAgent);
return (/(ios|ipod|ipad|iphone|android)/i).test(navigator.userAgent);
}

function isConnectedTV() {
return (/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(global.navigator.userAgent);
return (/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(navigator.userAgent);
}

function getDoNotTrack() {
return navigator.doNotTrack === '1' || window.doNotTrack === '1' || navigator.msDoNoTrack === '1' || navigator.doNotTrack === 'yes';
}

function isVideoBid(bid) {
return bid.mediaTypes && bid.mediaTypes.video;
}

function createRequestParams(bid) {
let size = getSize(bid.sizes);
function createVideoRequestData(bid) {
let size = getFirstSize(bid);
let topLocation = utils.getTopWindowLocation();
return {
isPrebid: true,
appId: bid.params.appId,
domain: document.location.hostname,
id: utils.getUniqueIdentifierStr(),
imp: [{
video: {
w: size.width,
h: size.height
w: size.w,
h: size.h
},
bidfloor: bid.params.bidfloor
}],
site: {
page: utils.getTopWindowLocation().host
page: topLocation.host
},
device: {
ua: global.navigator.userAgent,
devicetype: isMobile() ? 1 : isConnectedTV() ? 3 : 2
ua: navigator.userAgent,
devicetype: isMobile() ? 1 : isConnectedTV() ? 3 : 2,
geo: {}
},
cur: ['USD']
};
}

function createBannerRequestData(bids) {
let topLocation = utils.getTopWindowLocation();
let referrer = utils.getTopWindowReferrer();
let slots = bids.map(bid => {
return {
slot: bid.adUnitCode,
id: bid.params.appId,
bidfloor: bid.params.bidfloor,
sizes: getSizes(bid)
};
});
return {
slots: slots,
page: topLocation.href,
domain: topLocation.hostname,
search: topLocation.search,
secure: topLocation.protocol === 'https:' ? 1 : 0,
referrer: referrer,
ua: navigator.userAgent,
deviceOs: getOsVersion(),
isMobile: isMobile() ? 1 : 0,
dnt: getDoNotTrack() ? 1 : 0,
adapterVersion: ADAPTER_VERSION,
adapterName: ADAPTER_NAME
};
}

registerBidder(spec);
12 changes: 12 additions & 0 deletions modules/beachfrontBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ Module that connects to Beachfront's demand sources
}
}
]
}, {
code: 'test-banner',
sizes: [300, 250],
bids: [
{
bidder: 'beachfront',
params: {
bidfloor: 0.01,
appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3'
}
}
]
}
];
```
Loading