diff --git a/modules/gridBidAdapter.js b/modules/gridBidAdapter.js index bb3bba5b550..fd1a382d995 100644 --- a/modules/gridBidAdapter.js +++ b/modules/gridBidAdapter.js @@ -1,8 +1,13 @@ import * as utils from '../src/utils'; import {registerBidder} from '../src/adapters/bidderFactory'; +import { Renderer } from '../src/Renderer'; +import { VIDEO, BANNER } from '../src/mediaTypes'; + const BIDDER_CODE = 'grid'; const ENDPOINT_URL = '//grid.bidswitch.net/hb'; const TIME_TO_LIVE = 360; +const RENDERER_URL = '//cdn.adnxs.com/renderer/video/ANOutstreamVideo.js'; + const LOG_ERROR_MESS = { noAuid: 'Bid from response has no auid parameter - ', noAdm: 'Bid from response has no adm parameter - ', @@ -16,6 +21,7 @@ const LOG_ERROR_MESS = { }; export const spec = { code: BIDDER_CODE, + supportedMediaTypes: [ BANNER, VIDEO ], /** * Determines whether or not the given bid request is valid. * @@ -124,19 +130,39 @@ function _addBidResponse(serverBid, bidsMap, bidResponses) { const awaitingBids = bidsMap[serverBid.auid]; if (awaitingBids) { awaitingBids.forEach(bid => { + const size = bid.sizes[0]; + if (serverBid.w && serverBid.h) { + size[0] = serverBid.w; + size[1] = serverBid.h; + } const bidResponse = { requestId: bid.bidId, // bid.bidderRequestId, bidderCode: spec.code, cpm: serverBid.price, - width: serverBid.w, - height: serverBid.h, + width: size[0], + height: size[1], creativeId: serverBid.auid, // bid.bidId, currency: 'USD', netRevenue: false, ttl: TIME_TO_LIVE, - ad: serverBid.adm, dealId: serverBid.dealid }; + if (serverBid.content_type === 'video') { + bidResponse.vastXml = serverBid.adm; + bidResponse.mediaType = VIDEO; + bidResponse.adResponse = { + content: bidResponse.vastXml + }; + if (!bid.renderer && (!bid.mediaTypes || !bid.mediaTypes.video || bid.mediaTypes.video.context === 'outstream')) { + bidResponse.renderer = createRenderer(bidResponse, { + id: bid.bidId, + url: RENDERER_URL + }); + } + } else { + bidResponse.ad = serverBid.adm; + bidResponse.mediaType = BANNER; + } bidResponses.push(bidResponse); }); } else { @@ -148,4 +174,29 @@ function _addBidResponse(serverBid, bidsMap, bidResponses) { } } +function outstreamRender (bid) { + bid.renderer.push(() => { + window.ANOutstreamVideo.renderAd({ + targetId: bid.adUnitCode, + adResponse: bid.adResponse + }); + }); +} + +function createRenderer (bid, rendererParams) { + const renderer = Renderer.install({ + id: rendererParams.id, + url: rendererParams.url, + loaded: false + }); + + try { + renderer.setRender(outstreamRender); + } catch (err) { + utils.logWarn('Prebid Error calling setRender on renderer', err); + } + + return renderer; +} + registerBidder(spec); diff --git a/modules/gridBidAdapter.md b/modules/gridBidAdapter.md index 9b7b0e0515e..4720ee3d808 100755 --- a/modules/gridBidAdapter.md +++ b/modules/gridBidAdapter.md @@ -7,6 +7,7 @@ Maintainer: grid-tech@themediagrid.com # Description Module that connects to Grid demand source to fetch bids. +Grid bid adapter supports Banner and Video (instream and outstream). # Test Parameters ``` @@ -35,6 +36,19 @@ Module that connects to Grid demand source to fetch bids. } } ] - } + }, + { + code: 'test-div', + sizes: [[728, 90]], + mediaTypes: { video: {} }, + bids: [ + { + bidder: "grid", + params: { + uid: 11 + } + } + ] + } ]; ``` \ No newline at end of file diff --git a/test/spec/modules/gridBidAdapter_spec.js b/test/spec/modules/gridBidAdapter_spec.js index f4401dfe677..9be195b4bd2 100644 --- a/test/spec/modules/gridBidAdapter_spec.js +++ b/test/spec/modules/gridBidAdapter_spec.js @@ -128,7 +128,7 @@ describe('TheMediaGrid Adapter', function () { describe('interpretResponse', function () { const responses = [ - {'bid': [{'price': 1.15, 'adm': '