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

Vertamedia adapter outstream support #1860

Merged
merged 26 commits into from
Dec 6, 2017
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
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,
descriptionUrl: bidResponse.url,
creativeId: bidResponse.cmpId,
Expand All @@ -116,6 +122,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 @@ -81,7 +81,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