diff --git a/modules/zeta_global_sspBidAdapter.js b/modules/zeta_global_sspBidAdapter.js index 4d5966e03e9..e1ca61357f0 100644 --- a/modules/zeta_global_sspBidAdapter.js +++ b/modules/zeta_global_sspBidAdapter.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 (const 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, @@ -178,6 +217,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/zeta_global_sspBidAdapter_spec.js b/test/spec/modules/zeta_global_sspBidAdapter_spec.js index 740ea855fca..dcb0183fb4c 100644 --- a/test/spec/modules/zeta_global_sspBidAdapter_spec.js +++ b/test/spec/modules/zeta_global_sspBidAdapter_spec.js @@ -55,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); @@ -186,4 +216,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[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.undefined; + }); });