Skip to content

Commit

Permalink
Vertamedia adapter outstream support (#1860)
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;

* add outstream mediaType support

* add outstream mediaType support

* Resolve conflicts

* fix test
  • Loading branch information
Millerrok authored and matthewlane committed Dec 6, 2017
1 parent 67879a9 commit 25e24d9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
44 changes: 41 additions & 3 deletions modules/vertamediaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import {VIDEO} from 'src/mediaTypes';
import {Renderer} from 'src/Renderer';

const URL = '//rtb.vertamedia.com/hb/';
const BIDDER_CODE = 'vertamedia';
Expand Down Expand Up @@ -37,6 +38,10 @@ export const spec = {
interpretResponse: function (serverResponse, {bidderRequest}) {
serverResponse = serverResponse.body;
const isInvalidValidResp = !serverResponse || !serverResponse.bids || !serverResponse.bids.length;
const videoMediaType = utils.deepAccess(bidderRequest.bids[0], 'mediaTypes.video');
const context = utils.deepAccess(bidderRequest.bids[0], 'mediaTypes.video.context');
const isMediaTypeOutstream = (videoMediaType && context === 'outstream');

let bids = [];

if (isInvalidValidResp) {
Expand All @@ -50,7 +55,7 @@ export const spec = {

serverResponse.bids.forEach(serverBid => {
if (serverBid.cpm !== 0) {
const bid = createBid(serverBid);
const bid = createBid(isMediaTypeOutstream, serverBid);
bids.push(bid);
}
});
Expand Down Expand Up @@ -99,11 +104,12 @@ function getSize(requestSizes) {

/**
* Configure new bid by response
* @param isMediaTypeOutstream {boolean}
* @param bidResponse {object}
* @returns {object}
*/
function createBid(bidResponse) {
return {
function createBid(isMediaTypeOutstream, bidResponse) {
let bid = {
requestId: bidResponse.requestId,
creativeId: bidResponse.cmpId,
vastUrl: bidResponse.vastUrl,
Expand All @@ -115,6 +121,38 @@ function createBid(bidResponse) {
netRevenue: true,
ttl: 3600
};

if (isMediaTypeOutstream) {
Object.assign(bid, {
adResponse: bidResponse,
renderer: newRenderer(bidResponse.requestId)
});
}

return bid;
}

function newRenderer(requestId) {
const renderer = Renderer.install({
id: requestId,
url: '//player.vertamedia.com/outstream-unit/2.01/outstream.min.js',
loaded: false,
});

renderer.setRender(outstreamRender);

return renderer;
}

function outstreamRender(bid) {
bid.renderer.push(() => {
window.VOutstreamAPI.initOutstreams([{
width: bid.width,
height: bid.height,
vastUrl: bid.vastUrl,
elId: bid.adUnitCode
}]);
});
}

registerBidder(spec);
14 changes: 14 additions & 0 deletions modules/vertamediaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,19 @@ This adapter provides a solution for accessing Video demand
aid: 332842
}
}]
}{
code: 'outstream-test-div',
sizes: [[640, 480]], // ad size
mediaTypes: {
video: {
context: 'outstream'
}
},
bids: [{
bidder: 'vertamedia', // adapter name
params: {
aid: 332842
}
}]
}];
```
6 changes: 5 additions & 1 deletion test/spec/modules/vertamediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ describe('vertamediaBidAdapter', () => {
});

describe('interpretResponse', () => {
let bidderRequest = {bidderCode: 'bidderCode'};
let bidderRequest = {
bidderCode: 'bidderCode',
bids: [{mediaTypes: {video: {}}}]
};

it('should get correct bid response', () => {
const result = spec.interpretResponse({body: serverResponse}, {bidderRequest});
const eq = [{
Expand Down

0 comments on commit 25e24d9

Please sign in to comment.