diff --git a/modules/adfBidAdapter.js b/modules/adfBidAdapter.js index 8b3550e6108..5893891eba6 100644 --- a/modules/adfBidAdapter.js +++ b/modules/adfBidAdapter.js @@ -5,10 +5,13 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { - NATIVE + NATIVE, BANNER, VIDEO } from '../src/mediaTypes.js'; import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; +import { Renderer } from '../src/Renderer.js'; + +const { getConfig } = config; const BIDDER_CODE = 'adf'; const GVLID = 50; @@ -45,28 +48,58 @@ const NATIVE_PARAMS = { name: 'data' } }; +const OUTSTREAM_RENDERER_URL = 'https://s2.adform.net/banners/scripts/video/outstream/render.js'; export const spec = { code: BIDDER_CODE, aliases: BIDDER_ALIAS, gvlid: GVLID, - supportedMediaTypes: [ NATIVE ], + supportedMediaTypes: [ NATIVE, BANNER, VIDEO ], isBidRequestValid: bid => !!bid.params.mid, buildRequests: (validBidRequests, bidderRequest) => { - const page = bidderRequest.refererInfo.referer; + let app, site; + + const commonFpd = getConfig('ortb2') || {}; + let { user } = commonFpd; + + if (typeof getConfig('app') === 'object') { + app = getConfig('app') || {}; + if (commonFpd.app) { + utils.mergeDeep(app, commonFpd.app); + } + } else { + site = getConfig('site') || {}; + if (commonFpd.site) { + utils.mergeDeep(site, commonFpd.site); + } + + if (!site.page) { + site.page = bidderRequest.refererInfo.referer; + } + } + + const device = getConfig('device') || {}; + device.w = device.w || window.innerWidth; + device.h = device.h || window.innerHeight; + device.ua = device.ua || navigator.userAgent; + const adxDomain = setOnAny(validBidRequests, 'params.adxDomain') || 'adx.adform.net'; - const ua = navigator.userAgent; + const pt = setOnAny(validBidRequests, 'params.pt') || setOnAny(validBidRequests, 'params.priceType') || 'net'; - const tid = validBidRequests[0].transactionId; // ??? check with ssp + const tid = validBidRequests[0].transactionId; const test = setOnAny(validBidRequests, 'params.test'); - const publisher = setOnAny(validBidRequests, 'params.publisher'); - const siteId = setOnAny(validBidRequests, 'params.siteId'); - const currency = config.getConfig('currency.adServerCurrency'); + const currency = getConfig('currency.adServerCurrency'); const cur = currency && [ currency ]; const eids = setOnAny(validBidRequests, 'userIdAsEids'); const imp = validBidRequests.map((bid, id) => { bid.netRevenue = pt; + + const imp = { + id: id + 1, + tagid: bid.params.mid + }; + const assets = utils._map(bid.nativeParams, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { @@ -102,21 +135,51 @@ export const spec = { } }).filter(Boolean); - return { - id: id + 1, - tagid: bid.params.mid, - native: { + if (assets.length) { + imp.native = { request: { assets } - } - }; + }; + + bid.mediaType = NATIVE; + return imp; + } + + const bannerParams = utils.deepAccess(bid, 'mediaTypes.banner'); + + if (bannerParams && bannerParams.sizes) { + const sizes = utils.parseSizesInput(bannerParams.sizes); + const format = sizes.map(size => { + const [ width, height ] = size.split('x'); + const w = parseInt(width, 10); + const h = parseInt(height, 10); + return { w, h }; + }); + + imp.banner = { + format + }; + bid.mediaType = BANNER; + + return imp; + } + + const videoParams = utils.deepAccess(bid, 'mediaTypes.video'); + if (videoParams) { + imp.video = videoParams; + bid.mediaType = VIDEO; + + return imp; + } }); const request = { id: bidderRequest.auctionId, - site: { id: siteId, page, publisher }, - device: { ua }, + site, + app, + user, + device, source: { tid, fd: 1 }, ext: { pt }, cur, @@ -128,8 +191,8 @@ export const spec = { request.test = 1; } if (utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies') !== undefined) { - request.user = { ext: { consent: bidderRequest.gdprConsent.consentString } }; - request.regs = { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies & 1 } }; + utils.deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); } if (bidderRequest.uspConsent) { @@ -164,16 +227,35 @@ export const spec = { return bids.map((bid, id) => { const bidResponse = bidResponses[id]; if (bidResponse) { - return { + const result = { requestId: bid.bidId, cpm: bidResponse.price, creativeId: bidResponse.crid, ttl: 360, netRevenue: bid.netRevenue === 'net', currency: cur, - mediaType: NATIVE, - native: parseNative(bidResponse) + mediaType: bid.mediaType, + width: bidResponse.w, + height: bidResponse.h, + dealId: bidResponse.dealid, + meta: { + mediaType: bid.mediaType, + advertiserDomains: bidResponse.adomain + } }; + + if (bidResponse.native) { + result.native = parseNative(bidResponse); + } else { + result[ bid.mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm; + } + + if (!bid.renderer && bid.mediaType === VIDEO && utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { + result.renderer = Renderer.install({id: bid.bidId, url: OUTSTREAM_RENDERER_URL, adUnitCode: bid.adUnitCode}); + result.renderer.setRender(renderer); + } + + return result; } }).filter(Boolean); } @@ -212,3 +294,9 @@ function setOnAny(collection, key) { function flatten(arr) { return [].concat(...arr); } + +function renderer(bid) { + bid.renderer.push(() => { + window.Adform.renderOutstream(bid); + }); +} diff --git a/modules/adfBidAdapter.md b/modules/adfBidAdapter.md index 190aa91ea57..10264e6f486 100644 --- a/modules/adfBidAdapter.md +++ b/modules/adfBidAdapter.md @@ -7,15 +7,12 @@ Maintainer: Scope.FL.Scripts@adform.com # Description Module that connects to Adform demand sources to fetch bids. -Only native format is supported. Using OpenRTB standard. Previous adapter name - adformOpenRTB. +Banner, video and native formats are supported. Using OpenRTB standard. Previous adapter name - adformOpenRTB. # Test Parameters ``` - var adUnits = [ + var adUnits = [{ code: '/19968336/prebid_native_example_1', - sizes: [ - [360, 360] - ], mediaTypes: { native: { image: { @@ -44,16 +41,36 @@ Only native format is supported. Using OpenRTB standard. Previous adapter name - bids: [{ bidder: 'adf', params: { - mid: 606169, // required - adxDomain: 'adx.adform.net', // optional - siteId: '23455', // optional - priceType: 'gross' // optional, default is 'net' - publisher: { // optional block - id: "2706", - name: "Publishers Name", - domain: "publisher.com" - } + mid: 606169, // required + adxDomain: 'adx.adform.net' // optional + } + }] + }, { + code: '/19968336/prebid_banner_example_1', + mediaTypes: { + banner: { + sizes: [[ 300, 250 ]] + } + } + bids: [{ + bidder: 'adf', + params: { + mid: 1038466 + } + }] + }, { + code: '/19968336/prebid_video_example_1', + mediaTypes: { + video: { + context: 'outstream', + mimes: ['video/mp4'] + } + } + bids: [{ + bidder: 'adf', + params: { + mid: 822732 } }] - ]; + }]; ``` diff --git a/test/spec/modules/adfBidAdapter_spec.js b/test/spec/modules/adfBidAdapter_spec.js index 2c141d31bf8..ae92af32a1e 100644 --- a/test/spec/modules/adfBidAdapter_spec.js +++ b/test/spec/modules/adfBidAdapter_spec.js @@ -35,11 +35,13 @@ describe('Adf adapter', function () { }); describe('buildRequests', function () { + beforeEach(function () { + config.resetConfig(); + }); it('should send request with correct structure', function () { let validBidRequests = [{ bidId: 'bidId', params: { - siteId: 'siteId', adxDomain: '10.8.57.207' } }]; @@ -53,7 +55,7 @@ describe('Adf adapter', function () { describe('user privacy', function () { it('should send GDPR Consent data to adform if gdprApplies', function () { - let validBidRequests = [{ bidId: 'bidId', params: { siteId: 'siteId', test: 1 } }]; + let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }]; let bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { referer: 'page' } }; let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); @@ -63,7 +65,7 @@ describe('Adf adapter', function () { }); it('should send gdpr as number', function () { - let validBidRequests = [{ bidId: 'bidId', params: { siteId: 'siteId', test: 1 } }]; + let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }]; let bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { referer: 'page' } }; let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); @@ -72,7 +74,7 @@ describe('Adf adapter', function () { }); it('should send CCPA Consent data to adform', function () { - let validBidRequests = [{ bidId: 'bidId', params: { siteId: 'siteId', test: 1 } }]; + let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }]; let bidderRequest = { uspConsent: '1YA-', refererInfo: { referer: 'page' } }; let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); @@ -118,7 +120,7 @@ describe('Adf adapter', function () { it('should add test and is_debug to request, if test is set in parameters', function () { let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', test: 1 } + params: { test: 1 } }]; let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); @@ -151,26 +153,66 @@ describe('Adf adapter', function () { }); it('should send info about device', function () { + config.setConfig({ + device: { w: 100, h: 100 } + }); let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId' } + params: { mid: '1000' } }]; let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); assert.equal(request.device.ua, navigator.userAgent); + assert.equal(request.device.w, 100); + assert.equal(request.device.h, 100); + }); + + it('should send app info', function () { + config.setConfig({ + app: { id: 'appid' }, + ortb2: { app: { name: 'appname' } } + }); + let validBidRequests = [{ + bidId: 'bidId', + params: { mid: '1000' } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.equal(request.app.id, 'appid'); + assert.equal(request.app.name, 'appname'); + assert.equal(request.site, undefined); }); + it('should send info about the site', function () { + config.setConfig({ + site: { + id: '123123', + publisher: { + domain: 'publisher.domain.com' + } + }, + ortb2: { + site: { + publisher: { + name: 'publisher\'s name' + } + } + } + }); let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', publisher: {id: '123123', domain: 'publisher.domain.com', name: 'publisher\'s name'} } + params: { mid: '1000' } }]; let refererInfo = { referer: 'page' }; let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo }).data); assert.deepEqual(request.site, { page: refererInfo.referer, - publisher: validBidRequests[0].params.publisher, - id: validBidRequests[0].params.siteId + publisher: { + domain: 'publisher.domain.com', + name: 'publisher\'s name' + }, + id: '123123' }); }); @@ -213,7 +255,7 @@ describe('Adf adapter', function () { it('should send correct priceType value', function () { let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', priceType: 'net' } + params: { priceType: 'net' } }]; let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); @@ -237,13 +279,16 @@ describe('Adf adapter', function () { it('should add incrementing values of id', function () { let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId' } + params: { mid: '1000' }, + mediaTypes: {video: {}} }, { bidId: 'bidId2', - params: { siteId: 'siteId' } + params: { mid: '1000' }, + mediaTypes: {video: {}} }, { bidId: 'bidId3', - params: { siteId: 'siteId' } + params: { mid: '1000' }, + mediaTypes: {video: {}} }]; let imps = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; @@ -253,21 +298,106 @@ describe('Adf adapter', function () { }); it('should add mid', function () { - let validBidRequests = [{ bidId: 'bidId', params: { siteId: 'siteId', mid: 1000 } }, - { bidId: 'bidId2', params: { siteId: 'siteId', mid: 1001 } }, - { bidId: 'bidId3', params: { siteId: 'siteId', mid: 1002 } }]; + let validBidRequests = [{ bidId: 'bidId', params: {mid: 1000}, mediaTypes: {video: {}} }, + { bidId: 'bidId2', params: {mid: 1001}, mediaTypes: {video: {}} }, + { bidId: 'bidId3', params: {mid: 1002}, mediaTypes: {video: {}} }]; let imps = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; for (let i = 0; i < 3; i++) { assert.equal(imps[i].tagid, validBidRequests[i].params.mid); } }); + describe('multiple media types', function () { + it('should use single media type for bidding', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { mid: 1000 }, + mediaTypes: { + banner: { + sizes: [[100, 100], [200, 300]] + }, + video: {} + } + }, { + bidId: 'bidId1', + params: { mid: 1000 }, + mediaTypes: { + video: {}, + native: {} + } + }, { + bidId: 'bidId2', + params: { mid: 1000 }, + nativeParams: { + title: { required: true, len: 140 } + }, + mediaTypes: { + banner: { + sizes: [[100, 100], [200, 300]] + }, + native: {} + } + }]; + let [ banner, video, native ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; + + assert.ok(banner.banner); + assert.equal(banner.video, undefined); + assert.equal(banner.native, undefined); + assert.ok(video.video); + assert.equal(video.banner, undefined); + assert.equal(video.native, undefined); + assert.ok(native.native); + assert.equal(native.video, undefined); + assert.equal(native.banner, undefined); + }); + }); + + describe('banner', function () { + it('should convert sizes to openrtb format', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { mid: 1000 }, + mediaTypes: { + banner: { + sizes: [[100, 100], [200, 300]] + } + } + }]; + let { banner } = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0]; + assert.deepEqual(banner, { + format: [ { w: 100, h: 100 }, { w: 200, h: 300 } ] + }); + }); + }); + + describe('video', function () { + it('should pass video mediatype config', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { mid: 1000 }, + mediaTypes: { + video: { + playerSize: [640, 480], + context: 'outstream', + mimes: ['video/mp4'] + } + } + }]; + let { video } = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0]; + assert.deepEqual(video, { + playerSize: [640, 480], + context: 'outstream', + mimes: ['video/mp4'] + }); + }); + }); + describe('native', function () { describe('assets', function () { it('should set correct asset id', function () { let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -283,7 +413,7 @@ describe('Adf adapter', function () { it('should add required key if it is necessary', function () { let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -303,7 +433,7 @@ describe('Adf adapter', function () { it('should map img and data assets', function () { let validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: true, sizes: [150, 50] }, @@ -330,7 +460,7 @@ describe('Adf adapter', function () { it('should flatten sizes and utilise first pair', function () { const validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { image: { sizes: [[200, 300], [100, 200]] @@ -348,7 +478,7 @@ describe('Adf adapter', function () { it('should utilise aspect_ratios', function () { const validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { image: { aspect_ratios: [{ @@ -380,7 +510,7 @@ describe('Adf adapter', function () { it('should not throw error if aspect_ratios config is not defined', function () { const validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { image: { aspect_ratios: [] @@ -398,7 +528,7 @@ describe('Adf adapter', function () { it('should expect any dimensions if min_width not passed', function () { const validBidRequests = [{ bidId: 'bidId', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { image: { aspect_ratios: [{ @@ -441,7 +571,7 @@ describe('Adf adapter', function () { bids: [ { bidId: 'bidId1', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -450,7 +580,7 @@ describe('Adf adapter', function () { }, { bidId: 'bidId2', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -482,7 +612,7 @@ describe('Adf adapter', function () { bids: [ { bidId: 'bidId1', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -491,7 +621,7 @@ describe('Adf adapter', function () { }, { bidId: 'bidId2', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -500,7 +630,7 @@ describe('Adf adapter', function () { }, { bidId: 'bidId3', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -509,7 +639,7 @@ describe('Adf adapter', function () { }, { bidId: 'bidId4', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -543,7 +673,9 @@ describe('Adf adapter', function () { assets: [], link: { url: 'link' }, imptrackers: ['imptrackers url1', 'imptrackers url2'] - } + }, + dealid: 'deal-id', + adomain: [ 'demo.com' ] } ] }], @@ -555,7 +687,8 @@ describe('Adf adapter', function () { bids: [ { bidId: 'bidId1', - params: { siteId: 'siteId', mid: 1000 }, + params: { mid: 1000 }, + mediaType: 'native', nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -574,6 +707,9 @@ describe('Adf adapter', function () { assert.deepEqual(bids[0].netRevenue, false); assert.deepEqual(bids[0].currency, serverResponse.body.cur); assert.deepEqual(bids[0].mediaType, 'native'); + assert.deepEqual(bids[0].meta.mediaType, 'native'); + assert.deepEqual(bids[0].meta.advertiserDomains, [ 'demo.com' ]); + assert.deepEqual(bids[0].dealId, 'deal-id'); }); it('should set correct native params', function () { const bid = [ @@ -678,5 +814,96 @@ describe('Adf adapter', function () { const result = spec.interpretResponse(serverResponse, bidRequest)[0]; assert.ok(!result); }); + + describe('banner', function () { + it('should set ad content on response', function () { + let serverResponse = { + body: { + seatbid: [{ + bid: [{ impid: '1', adm: '' }] + }] + } + }; + let bidRequest = { + data: {}, + bids: [ + { + bidId: 'bidId1', + params: { mid: 1000 }, + mediaType: 'banner' + } + ] + }; + + bids = spec.interpretResponse(serverResponse, bidRequest); + assert.equal(bids.length, 1); + assert.equal(bids[0].ad, ''); + }); + }); + + describe('video', function () { + it('should set vastXml on response', function () { + let serverResponse = { + body: { + seatbid: [{ + bid: [{ impid: '1', adm: '' }] + }] + } + }; + let bidRequest = { + data: {}, + bids: [ + { + bidId: 'bidId1', + params: { mid: 1000 }, + mediaType: 'video' + } + ] + }; + + bids = spec.interpretResponse(serverResponse, bidRequest); + assert.equal(bids.length, 1); + assert.equal(bids[0].vastXml, ''); + }); + + it('should add renderer for outstream bids', function () { + let serverResponse = { + body: { + seatbid: [{ + bid: [{ impid: '1', adm: '' }, { impid: '2', adm: '' }] + }] + } + }; + let bidRequest = { + data: {}, + bids: [ + { + bidId: 'bidId1', + params: { mid: 1000 }, + mediaType: 'video', + mediaTypes: { + video: { + context: 'outstream' + } + } + }, + { + bidId: 'bidId2', + params: { mid: 1000 }, + mediaType: 'video', + mediaTypes: { + video: { + constext: 'instream' + } + } + } + ] + }; + + bids = spec.interpretResponse(serverResponse, bidRequest); + assert.ok(bids[0].renderer); + assert.equal(bids[1].renderer, undefined); + }); + }); }); });