From a1842fec5482a9c9b0e63327f7d99999491f0ba0 Mon Sep 17 00:00:00 2001 From: Surovenko Alexey Date: Thu, 12 Aug 2021 20:29:33 +0600 Subject: [PATCH 1/5] Zeta Ssp Bid Adapter: video support --- modules/zetaSspBidAdapter.js | 90 ++++++++++++++++++++- test/spec/modules/zetaSspBidAdapter_spec.js | 45 +++++++++++ 2 files changed, 131 insertions(+), 4 deletions(-) diff --git a/modules/zetaSspBidAdapter.js b/modules/zetaSspBidAdapter.js index 76ceea0fdd1..58567740a1d 100644 --- a/modules/zetaSspBidAdapter.js +++ b/modules/zetaSspBidAdapter.js @@ -1,6 +1,6 @@ import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {BANNER} from '../src/mediaTypes.js'; +import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; const BIDDER_CODE = 'zeta_global_ssp'; @@ -11,9 +11,34 @@ const DEFAULT_CUR = 'USD'; const TTL = 200; const NET_REV = true; +const DATA_TYPES = { + 'NUMBER': 'number', + 'STRING': 'string', + 'BOOLEAN': 'boolean', + 'ARRAY': 'array', + 'OBJECT': 'object' +}; +const VIDEO_CUSTOM_PARAMS = { + 'mimes': DATA_TYPES.ARRAY, + 'minduration': DATA_TYPES.NUMBER, + 'maxduration': DATA_TYPES.NUMBER, + 'startdelay': DATA_TYPES.NUMBER, + 'playbackmethod': DATA_TYPES.ARRAY, + 'api': DATA_TYPES.ARRAY, + 'protocols': DATA_TYPES.ARRAY, + 'w': DATA_TYPES.NUMBER, + 'h': DATA_TYPES.NUMBER, + 'battr': DATA_TYPES.ARRAY, + 'linearity': DATA_TYPES.NUMBER, + 'placement': DATA_TYPES.NUMBER, + 'minbitrate': DATA_TYPES.NUMBER, + 'maxbitrate': DATA_TYPES.NUMBER, + 'skip': DATA_TYPES.NUMBER +} + export const spec = { code: BIDDER_CODE, - supportedMediaTypes: [BANNER], + supportedMediaTypes: [BANNER, VIDEO], /** * Determines whether or not the given bid request is valid. @@ -45,9 +70,23 @@ export const spec = { const params = request.params; const impData = { id: request.bidId, - secure: secure, - banner: buildBanner(request) + secure: secure }; + if (request.mediaTypes) { + for (mediaType in request.mediaTypes) { + switch (mediaType) { + case BANNER: + impData.banner = buildBanner(request); + break; + case VIDEO: + impData.video = buildVideo(request); + break; + } + } + } + if (!impData.banner && !impData.video) { + impData.banner = buildBanner(request); + } const fpd = config.getLegacyFpd(config.getConfig('ortb2')) || {}; let payload = { id: bidderRequest.auctionId, @@ -179,6 +218,49 @@ function buildBanner(request) { }; } +function buildVideo(request) { + let video = {}; + const videoParams = utils.deepAccess(request, 'mediaTypes.video', {}); + for (const key in VIDEO_CUSTOM_PARAMS) { + if (videoParams.hasOwnProperty(key)) { + video[key] = checkParamDataType(key, videoParams[key], VIDEO_CUSTOM_PARAMS[key]); + } + } + if (videoParams.playerSize) { + if (utils.isArray(videoParams.playerSize[0])) { + video.w = parseInt(videoParams.playerSize[0][0], 10); + video.h = parseInt(videoParams.playerSize[0][1], 10); + } else if (utils.isNumber(videoParams.playerSize[0])) { + video.w = parseInt(videoParams.playerSize[0], 10); + video.h = parseInt(videoParams.playerSize[1], 10); + } + } + return video; +} + +function checkParamDataType(key, value, datatype) { + let functionToExecute; + switch (datatype) { + case DATA_TYPES.BOOLEAN: + functionToExecute = utils.isBoolean; + break; + case DATA_TYPES.NUMBER: + functionToExecute = utils.isNumber; + break; + case DATA_TYPES.STRING: + functionToExecute = utils.isStr; + break; + case DATA_TYPES.ARRAY: + functionToExecute = utils.isArray; + break; + } + if (functionToExecute(value)) { + return value; + } + utils.logWarn('Ignoring param key: ' + key + ', expects ' + datatype + ', found ' + typeof value); + return undefined; +} + function provideEids(request, payload) { if (Array.isArray(request.userIdAsEids) && request.userIdAsEids.length > 0) { utils.deepSetValue(payload, 'user.ext.eids', request.userIdAsEids); diff --git a/test/spec/modules/zetaSspBidAdapter_spec.js b/test/spec/modules/zetaSspBidAdapter_spec.js index 9f25a489dab..a8e62ad44fa 100644 --- a/test/spec/modules/zetaSspBidAdapter_spec.js +++ b/test/spec/modules/zetaSspBidAdapter_spec.js @@ -1,4 +1,5 @@ import {spec} from '../../../modules/zetaSspBidAdapter.js' +import {expect} from "chai"; describe('Zeta Ssp Bid Adapter', function () { const eids = [ @@ -54,6 +55,36 @@ describe('Zeta Ssp Bid Adapter', function () { userIdAsEids: eids }]; + const videoRequest = [{ + bidId: 112233, + auctionId: 667788, + mediaTypes: { + video: { + context: 'instream', + playerSize: [[720, 340]], + mimes: ['video/mp4'], + minDuration: 5, + maxDuration: 30, + protocols: [2, 3] + } + }, + refererInfo: { + referer: 'http://www.zetaglobal.com/page?param=video' + }, + params: { + placement: 111, + user: { + uid: 222, + buyeruid: 333 + }, + tags: { + someTag: 444, + sid: 'publisherId' + }, + test: 1 + }, + }]; + it('Test the bid validation function', function () { const validBid = spec.isBidRequestValid(bannerRequest[0]); const invalidBid = spec.isBidRequestValid(null); @@ -176,4 +207,18 @@ describe('Zeta Ssp Bid Adapter', function () { expect(payload.user.buyeruid).to.eql(333); expect(payload.user.ext.consent).to.eql('consentString'); }); + + it('Test video object', function () { + const request = spec.buildRequests(videoRequest, videoRequest[0]); + const payload = JSON.parse(request.data); + + expect(payload.imp[0].video.minDuration).to.eql(videoRequest.mediaTypes.video.minDuration); + expect(payload.imp[0].video.maxDuration).to.eql(videoRequest.mediaTypes.video.maxDuration); + expect(payload.imp[0].video.protocols).to.eql(videoRequest.mediaTypes.video.protocols); + expect(payload.imp[0].video.mimes).to.eql(videoRequest.mediaTypes.video.mimes); + expect(payload.imp[0].video.w).to.eql(720); + expect(payload.imp[0].video.h).to.eql(340); + + expect(payload.imp[0].banner).to.be.empty; + }); }); From 3adea8bc72d18c44055455b870856be2fe5b4449 Mon Sep 17 00:00:00 2001 From: Surovenko Alexey Date: Thu, 12 Aug 2021 20:44:18 +0600 Subject: [PATCH 2/5] fixes(1) --- modules/zetaSspBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/zetaSspBidAdapter.js b/modules/zetaSspBidAdapter.js index 58567740a1d..9a555613ae1 100644 --- a/modules/zetaSspBidAdapter.js +++ b/modules/zetaSspBidAdapter.js @@ -72,7 +72,7 @@ export const spec = { id: request.bidId, secure: secure }; - if (request.mediaTypes) { + if (request.hasOwnProperty('mediaTypes')) { for (mediaType in request.mediaTypes) { switch (mediaType) { case BANNER: From 8b74cbc48559a77546266d5224e11cbcbdfbcd69 Mon Sep 17 00:00:00 2001 From: Surovenko Alexey Date: Thu, 12 Aug 2021 20:48:06 +0600 Subject: [PATCH 3/5] fixes(2) --- modules/zetaSspBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/zetaSspBidAdapter.js b/modules/zetaSspBidAdapter.js index 9a555613ae1..037714a8dd1 100644 --- a/modules/zetaSspBidAdapter.js +++ b/modules/zetaSspBidAdapter.js @@ -72,8 +72,8 @@ export const spec = { id: request.bidId, secure: secure }; - if (request.hasOwnProperty('mediaTypes')) { - for (mediaType in request.mediaTypes) { + if (request.mediaTypes) { + for (const mediaType in request.mediaTypes) { switch (mediaType) { case BANNER: impData.banner = buildBanner(request); From 90ae351b3a201d338fe7ec4f884efa320d94d49c Mon Sep 17 00:00:00 2001 From: Surovenko Alexey Date: Thu, 12 Aug 2021 21:01:39 +0600 Subject: [PATCH 4/5] fixes(3) --- test/spec/modules/zetaSspBidAdapter_spec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/spec/modules/zetaSspBidAdapter_spec.js b/test/spec/modules/zetaSspBidAdapter_spec.js index a8e62ad44fa..b770fb72544 100644 --- a/test/spec/modules/zetaSspBidAdapter_spec.js +++ b/test/spec/modules/zetaSspBidAdapter_spec.js @@ -1,5 +1,5 @@ import {spec} from '../../../modules/zetaSspBidAdapter.js' -import {expect} from "chai"; +import {expect} from 'chai'; describe('Zeta Ssp Bid Adapter', function () { const eids = [ @@ -63,8 +63,8 @@ describe('Zeta Ssp Bid Adapter', function () { context: 'instream', playerSize: [[720, 340]], mimes: ['video/mp4'], - minDuration: 5, - maxDuration: 30, + minduration: 5, + maxduration: 30, protocols: [2, 3] } }, @@ -212,13 +212,13 @@ describe('Zeta Ssp Bid Adapter', function () { const request = spec.buildRequests(videoRequest, videoRequest[0]); const payload = JSON.parse(request.data); - expect(payload.imp[0].video.minDuration).to.eql(videoRequest.mediaTypes.video.minDuration); - expect(payload.imp[0].video.maxDuration).to.eql(videoRequest.mediaTypes.video.maxDuration); - expect(payload.imp[0].video.protocols).to.eql(videoRequest.mediaTypes.video.protocols); - expect(payload.imp[0].video.mimes).to.eql(videoRequest.mediaTypes.video.mimes); + expect(payload.imp[0].video.minduration).to.eql(videoRequest[0].mediaTypes.video.minduration); + expect(payload.imp[0].video.maxduration).to.eql(videoRequest[0].mediaTypes.video.maxduration); + expect(payload.imp[0].video.protocols).to.eql(videoRequest[0].mediaTypes.video.protocols); + expect(payload.imp[0].video.mimes).to.eql(videoRequest[0].mediaTypes.video.mimes); expect(payload.imp[0].video.w).to.eql(720); expect(payload.imp[0].video.h).to.eql(340); - expect(payload.imp[0].banner).to.be.empty; + expect(payload.imp[0].banner).to.be.undefined; }); }); From 1c1d2c030e3fa5b422da3998f6f9c9abb274ab3f Mon Sep 17 00:00:00 2001 From: Surovenko Alexey Date: Tue, 17 Aug 2021 14:18:34 +0600 Subject: [PATCH 5/5] remove unused import --- test/spec/modules/zetaSspBidAdapter_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/modules/zetaSspBidAdapter_spec.js b/test/spec/modules/zetaSspBidAdapter_spec.js index b770fb72544..dcde4be7be1 100644 --- a/test/spec/modules/zetaSspBidAdapter_spec.js +++ b/test/spec/modules/zetaSspBidAdapter_spec.js @@ -1,5 +1,4 @@ import {spec} from '../../../modules/zetaSspBidAdapter.js' -import {expect} from 'chai'; describe('Zeta Ssp Bid Adapter', function () { const eids = [