Skip to content

Commit

Permalink
Vertamedia Adapter for 1.0 (prebid#1789)
Browse files Browse the repository at this point in the history
* Vertamedia prebid.js adapter initial

* sync

* remove https

* add http

* remove let

* fix typo

* fix spaces

* add descriptionUrl; remove log

* fix getSize

* add usege parseSizesInput

* Add support for vastTag

* Add moulty bid request; set vastUrl for bider;

* update for vertamedia adapter to Prebid 1.0

* Add vertamedia md file

* Add required fields

* Remove defaults; fix md file;
  • Loading branch information
Millerrok authored and dluxemburg committed Jul 17, 2018
1 parent 10a1ca5 commit ce3c69e
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 217 deletions.
216 changes: 109 additions & 107 deletions modules/vertamediaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,119 +1,121 @@
import Adapter from 'src/adapter';
import bidfactory from 'src/bidfactory';
import bidmanager from 'src/bidmanager';
import * as utils from 'src/utils';
import { ajax } from 'src/ajax';
import { STATUS } from 'src/constants';
import adaptermanager from 'src/adaptermanager';

const ENDPOINT = '//rtb.vertamedia.com/hb/';

function VertamediaAdapter() {
const baseAdapter = new Adapter('vertamedia');
let bidRequest;

baseAdapter.callBids = function (bidRequests) {
if (!bidRequests || !bidRequests.bids || bidRequests.bids.length === 0) {
return;
}

var RTBDataParams = prepareAndSaveRTBRequestParams(bidRequests.bids[0]);

if (!RTBDataParams) {
return;
}

ajax(ENDPOINT, handleResponse, RTBDataParams, {
contentType: 'text/plain',
withCredentials: true,
method: 'GET'
import {registerBidder} from 'src/adapters/bidderFactory';
import {VIDEO} from 'src/mediaTypes';

const URL = '//rtb.vertamedia.com/hb/';
const BIDDER_CODE = 'vertamedia';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [VIDEO],
isBidRequestValid: function (bid) {
return Boolean(bid && bid.params && bid.params.aid);
},

/**
* Make a server request from the list of BidRequests
* @param bidRequests
* @param bidderRequest
*/
buildRequests: function (bidRequests, bidderRequest) {
return bidRequests.map((bid) => {
return {
data: prepareRTBRequestParams(bid),
bidderRequest,
method: 'GET',
url: URL
}
});
};

function prepareAndSaveRTBRequestParams(bid) {
if (!bid || !bid.params || !bid.params.aid || !bid.placementCode) {
return;
},

/**
* Unpack the response from the server into a list of bids
* @param serverResponse
* @param bidderRequest
* @return {Bid[]} An array of bids which were nested inside the server
*/
interpretResponse: function (serverResponse, {bidderRequest}) {
serverResponse = serverResponse.body;
const isInvalidValidResp = !serverResponse || !serverResponse.bids || !serverResponse.bids.length;
let bids = [];

if (isInvalidValidResp) {
let extMessage = serverResponse && serverResponse.ext && serverResponse.ext.message ? `: ${serverResponse.ext.message}` : '';
let errorMessage = `in response for ${bidderRequest.bidderCode} adapter ${extMessage}`;

utils.logError(errorMessage);

return bids;
}

bidRequest = bid;

let size = getSize(bid.sizes);

bidRequest.width = size.width;
bidRequest.height = size.height;

return {
aid: bid.params.aid,
w: size.width,
h: size.height,
domain: document.location.hostname
};
}

function getSize(requestSizes) {
const parsed = {};
const size = utils.parseSizesInput(requestSizes)[0];

if (typeof size !== 'string') {
return parsed;
}

let parsedSize = size.toUpperCase().split('X');

return {
width: parseInt(parsedSize[0], 10) || undefined,
height: parseInt(parsedSize[1], 10) || undefined
};
}

/* Notify Prebid of bid responses so bids can get in the auction */
function handleResponse(response) {
var parsed;

try {
parsed = JSON.parse(response);
} catch (error) {
utils.logError(error);
}

if (!parsed || parsed.error || !parsed.bids || !parsed.bids.length) {
bidmanager.addBidResponse(bidRequest.placementCode, createBid(STATUS.NO_BID));
serverResponse.bids.forEach(serverBid => {
if (serverBid.cpm !== 0) {
const bid = createBid(serverBid);
bids.push(bid);
}
});

return;
}
return bids;
},
};

/**
* Prepare all parameters for request
* @param bid {object}
* @returns {object}
*/
function prepareRTBRequestParams(bid) {
let size = getSize(bid.sizes);

return {
domain: utils.getTopWindowLocation().hostname,
callbackId: bid.bidId,
aid: bid.params.aid,
h: size.height,
w: size.width
};
}

bidmanager.addBidResponse(bidRequest.placementCode, createBid(STATUS.GOOD, parsed.bids[0]));
/**
* Prepare size for request
* @param requestSizes {array}
* @returns {object} bid The bid to validate
*/
function getSize(requestSizes) {
const size = utils.parseSizesInput(requestSizes)[0];
const parsed = {};

if (typeof size !== 'string') {
return parsed;
}

function createBid(status, tag) {
var bid = bidfactory.createBid(status, tag);
let parsedSize = size.toUpperCase().split('X');

bid.code = baseAdapter.getBidderCode();
bid.bidderCode = bidRequest.bidder;

if (!tag || status !== STATUS.GOOD) {
return bid;
}

bid.mediaType = 'video';
bid.cpm = tag.cpm;
bid.creative_id = tag.cmpId;
bid.width = bidRequest.width;
bid.height = bidRequest.height;
bid.descriptionUrl = tag.url;
bid.vastUrl = tag.url;

return bid;
}

return Object.assign(this, {
callBids: baseAdapter.callBids,
setBidderCode: baseAdapter.setBidderCode
});
return {
height: parseInt(parsedSize[1], 10) || undefined,
width: parseInt(parsedSize[0], 10) || undefined
};
}

adaptermanager.registerBidAdapter(new VertamediaAdapter(), 'vertamedia', {
supportedMediaTypes: ['video']
});
/**
* Configure new bid by response
* @param bidResponse {object}
* @returns {object}
*/
function createBid(bidResponse) {
return {
requestId: bidResponse.requestId,
descriptionUrl: bidResponse.url,
creativeId: bidResponse.cmpId,
vastUrl: bidResponse.vastUrl,
height: bidResponse.height,
currency: bidResponse.cur,
width: bidResponse.width,
cpm: bidResponse.cpm,
mediaType: 'video',
netRevenue: true,
ttl: 3600
};
}

module.exports = VertamediaAdapter;
registerBidder(spec);
27 changes: 27 additions & 0 deletions modules/vertamediaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Overview

**Module Name**: VertaMedia Bidder Adapter
**Module Type**: Bidder Adapter
**Maintainer**: [email protected]

# Description

Get access to multiple demand partners across VertaMedia AdExchange and maximize your yield with VertaMedia header bidding adapter.

VertaMedia header bidding adapter connects with VertaMedia demand sources in order to fetch bids.
This adapter provides a solution for accessing Video demand


# Test Parameters
```
var adUnits = [{
code: 'div-test-div',
sizes: [[640, 480]], // ad size
bids: [{
bidder: 'vertamedia', // adapter name
params: {
aid: 332842
}
}]
}];
```
Loading

0 comments on commit ce3c69e

Please sign in to comment.