Skip to content

Commit

Permalink
Zeta Ssp Bid Adapter: support video (#7295)
Browse files Browse the repository at this point in the history
* Zeta Ssp Bid Adapter: video support

* fixes(1)

* fixes(2)

* fixes(3)

* remove unused import

Co-authored-by: Surovenko Alexey <[email protected]>
  • Loading branch information
asurovenko-zeta and surovenko authored Aug 23, 2021
1 parent 593e03f commit 96da9dd
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 4 deletions.
90 changes: 86 additions & 4 deletions modules/zeta_global_sspBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions test/spec/modules/zeta_global_sspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
});
});

0 comments on commit 96da9dd

Please sign in to comment.