From 28289a23db0ecd83098092996d52021dc35b7111 Mon Sep 17 00:00:00 2001 From: Tomas Kovtun Date: Thu, 17 Oct 2019 10:27:53 +0300 Subject: [PATCH] Adform adapter: add renderer for outstream bids --- modules/adformBidAdapter.js | 20 ++++++++++++++++++-- test/spec/modules/adformBidAdapter_spec.js | 9 +++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/modules/adformBidAdapter.js b/modules/adformBidAdapter.js index a3aef10e41e..0ac083e7e7c 100644 --- a/modules/adformBidAdapter.js +++ b/modules/adformBidAdapter.js @@ -1,8 +1,12 @@ 'use strict'; -import {registerBidder} from '../src/adapters/bidderFactory'; +import { registerBidder } from '../src/adapters/bidderFactory'; import { config } from '../src/config'; import { BANNER, VIDEO } from '../src/mediaTypes'; +import { Renderer } from '../src/Renderer'; +import * as utils from '../src/utils'; + +const OUTSTREAM_RENDERER_URL = 'https://s2.adform.net/banners/scripts/video/outstream/render.js'; const BIDDER_CODE = 'adform'; export const spec = { @@ -18,7 +22,7 @@ export const spec = { var request = []; var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ] ]; var bids = JSON.parse(JSON.stringify(validBidRequests)); - var bidder = (bids[0] && bids[0].bidder) || BIDDER_CODE + var bidder = (bids[0] && bids[0].bidder) || BIDDER_CODE; for (i = 0, l = bids.length; i < l; i++) { bid = bids[i]; if ((bid.params.priceType === 'net') || (bid.params.pt === 'net')) { @@ -112,6 +116,12 @@ export const spec = { vastXml: response.vast_content, mediaType: type }; + + if (!bid.renderer && utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { + bidObject.renderer = Renderer.install({id: bid.bidId, url: OUTSTREAM_RENDERER_URL}); + bidObject.renderer.setRender(renderer); + } + if (bidRequest.gdpr) { bidObject.gdpr = bidRequest.gdpr.gdpr; bidObject.gdpr_consent = bidRequest.gdpr.gdpr_consent; @@ -121,6 +131,12 @@ export const spec = { } return bidRespones; + function renderer(bid) { + bid.renderer.push(() => { + window.Adform.renderOutstream(bid); + }); + } + function verifySize(adItem, validSizes) { for (var j = 0, k = validSizes.length; j < k; j++) { if (adItem.width == validSizes[j][0] && diff --git a/test/spec/modules/adformBidAdapter_spec.js b/test/spec/modules/adformBidAdapter_spec.js index f50474ae500..17eef06c603 100644 --- a/test/spec/modules/adformBidAdapter_spec.js +++ b/test/spec/modules/adformBidAdapter_spec.js @@ -258,6 +258,13 @@ describe('Adform adapter', function () { }; }); + it('should set a renderer for an outstream context', function () { + serverResponse.body = [serverResponse.body[3]]; + bidRequest.bids = [bidRequest.bids[6]]; + let result = spec.interpretResponse(serverResponse, bidRequest); + assert.ok(result[0].renderer); + }); + describe('verifySizes', function () { it('should respond with empty response when sizes doesn\'t match', function () { serverResponse.body[0].response = 'banner'; @@ -309,6 +316,7 @@ describe('Adform adapter', function () { let sizes = [[250, 300], [300, 250], [300, 600]]; let placementCode = ['div-01', 'div-02', 'div-03', 'div-04', 'div-05']; + let mediaTypes = [{video: {context: 'outstream'}}]; let params = [{ mid: 1, url: 'some// there' }, {adxDomain: null, mid: 2, someVar: 'someValue', pt: 'gross'}, { adxDomain: null, mid: 3, pdom: 'home' }, {mid: 5, pt: 'net'}, {mid: 6, pt: 'gross'}]; bids = [ { @@ -388,6 +396,7 @@ describe('Adform adapter', function () { params: params[4], placementCode: placementCode[2], sizes: [], + mediaTypes: mediaTypes[0], transactionId: '5f33781f-9552-7ev3' } ];