From f45aa8a3fd2b6f2b128e833b0bc6137a158aa090 Mon Sep 17 00:00:00 2001 From: TheMediaGrid <44166371+TheMediaGrid@users.noreply.github.com> Date: Tue, 19 Feb 2019 17:51:29 +0300 Subject: [PATCH] Add video support in Grid Bid Adapter (#3545) * Added Grid Bid Adapter * remove priceType from TheMediaGrid Bid Adapter * Add video support in Grid Bid Adapter * Added test parameter for video slot * update Grid Bid Adapter to set size in response bid --- modules/gridBidAdapter.js | 57 ++++++++++++++- modules/gridBidAdapter.md | 16 +++- test/spec/modules/gridBidAdapter_spec.js | 93 +++++++++++++++++++++++- 3 files changed, 158 insertions(+), 8 deletions(-) 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': '
test content 1
', 'auid': 1, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 1, 'h': 250, 'w': 300, dealid: 11}], 'seat': '1'}, {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 2, 'h': 90, 'w': 728}], 'seat': '1'}, {'bid': [{'price': 0, 'auid': 3, 'h': 250, 'w': 300}], 'seat': '1'}, {'bid': [{'price': 0, 'adm': '
test content 4
', 'h': 250, 'w': 300}], 'seat': '1'}, @@ -157,12 +157,13 @@ describe('TheMediaGrid Adapter', function () { 'requestId': '659423fff799cb', 'cpm': 1.15, 'creativeId': 1, - 'dealId': undefined, + 'dealId': 11, 'width': 300, 'height': 250, 'ad': '
test content 1
', 'bidderCode': 'grid', 'currency': 'USD', + 'mediaType': 'banner', 'netRevenue': false, 'ttl': 360, } @@ -214,12 +215,13 @@ describe('TheMediaGrid Adapter', function () { 'requestId': '300bfeb0d71a5b', 'cpm': 1.15, 'creativeId': 1, - 'dealId': undefined, + 'dealId': 11, 'width': 300, 'height': 250, 'ad': '
test content 1
', 'bidderCode': 'grid', 'currency': 'USD', + 'mediaType': 'banner', 'netRevenue': false, 'ttl': 360, }, @@ -227,12 +229,13 @@ describe('TheMediaGrid Adapter', function () { 'requestId': '5703af74d0472a', 'cpm': 1.15, 'creativeId': 1, - 'dealId': undefined, + 'dealId': 11, 'width': 300, 'height': 250, 'ad': '
test content 1
', 'bidderCode': 'grid', 'currency': 'USD', + 'mediaType': 'banner', 'netRevenue': false, 'ttl': 360, }, @@ -246,6 +249,7 @@ describe('TheMediaGrid Adapter', function () { 'ad': '
test content 2
', 'bidderCode': 'grid', 'currency': 'USD', + 'mediaType': 'banner', 'netRevenue': false, 'ttl': 360, } @@ -255,6 +259,87 @@ describe('TheMediaGrid Adapter', function () { expect(result).to.deep.equal(expectedResponse); }); + it('should get correct video bid response', function () { + const bidRequests = [ + { + 'bidder': 'grid', + 'params': { + 'uid': '1' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '659423fff799cb', + 'bidderRequestId': '5f2009617a7c0a', + 'auctionId': '1cbd2feafe5e8b', + 'mediaTypes': { + 'video': { + 'context': 'instream' + } + } + }, + { + 'bidder': 'grid', + 'params': { + 'uid': '2' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '2bc598e42b6a', + 'bidderRequestId': '5f2009617a7c0a', + 'auctionId': '1cbd2feafe5e8b', + 'mediaTypes': { + 'video': { + 'context': 'instream' + } + } + } + ]; + const response = [ + {'bid': [{'price': 1.15, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 1, content_type: 'video', w: 300, h: 600}], 'seat': '2'}, + {'bid': [{'price': 1.00, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 2, content_type: 'video'}], 'seat': '2'} + ]; + const request = spec.buildRequests(bidRequests); + const expectedResponse = [ + { + 'requestId': '659423fff799cb', + 'cpm': 1.15, + 'creativeId': 1, + 'dealId': undefined, + 'width': 300, + 'height': 600, + 'bidderCode': 'grid', + 'currency': 'USD', + 'mediaType': 'video', + 'netRevenue': false, + 'ttl': 360, + 'vastXml': '\n<\/Ad>\n<\/VAST>', + 'adResponse': { + 'content': '\n<\/Ad>\n<\/VAST>' + } + }, + { + 'requestId': '2bc598e42b6a', + 'cpm': 1.00, + 'creativeId': 2, + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'bidderCode': 'grid', + 'currency': 'USD', + 'mediaType': 'video', + 'netRevenue': false, + 'ttl': 360, + 'vastXml': '\n<\/Ad>\n<\/VAST>', + 'adResponse': { + 'content': '\n<\/Ad>\n<\/VAST>' + } + } + ]; + + const result = spec.interpretResponse({'body': {'seatbid': response}}, request); + expect(result).to.deep.equal(expectedResponse); + }); + it('handles wrong and nobid responses', function () { const bidRequests = [ {