Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeta Ssp Bid Adapter: support video #7295

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
da0b4a5
Merge pull request #1 from prebid/master
asurovenko-zeta Mar 24, 2021
f4ec68e
Merge branch 'master' of git://github.com/prebid/Prebid.js
surovenko Apr 21, 2021
01990a9
Merge remote-tracking branch 'upstream/master'
surovenko May 18, 2021
62f969f
Merge remote-tracking branch 'upstream/master'
surovenko May 18, 2021
ec7c8f0
Merge remote-tracking branch 'upstream/master'
surovenko May 19, 2021
89fe5b1
Merge remote-tracking branch 'upstream/master'
surovenko May 24, 2021
6dc0255
Merge remote-tracking branch 'upstream/master'
surovenko Jun 1, 2021
8dc9ac2
Merge remote-tracking branch 'upstream/master'
surovenko Jun 3, 2021
35353f0
Merge remote-tracking branch 'upstream/master'
surovenko Jun 3, 2021
e6f982a
Merge remote-tracking branch 'upstream/master'
surovenko Jun 4, 2021
70e546c
Merge remote-tracking branch 'upstream/master'
surovenko Jun 7, 2021
cc56875
Merge remote-tracking branch 'upstream/master'
surovenko Jun 15, 2021
f4f2a1e
Merge remote-tracking branch 'upstream/master'
surovenko Jun 16, 2021
3f96c6a
Merge remote-tracking branch 'upstream/master'
surovenko Jul 8, 2021
8e503cd
Merge remote-tracking branch 'upstream/master'
surovenko Aug 3, 2021
1781bfd
Merge remote-tracking branch 'upstream/master'
surovenko Aug 12, 2021
a1842fe
Zeta Ssp Bid Adapter: video support
surovenko Aug 12, 2021
3adea8b
fixes(1)
surovenko Aug 12, 2021
8b74cbc
fixes(2)
surovenko Aug 12, 2021
90ae351
fixes(3)
surovenko Aug 12, 2021
1c1d2c0
remove unused import
surovenko Aug 17, 2021
459917b
Merge remote-tracking branch 'upstream/master'
surovenko Aug 17, 2021
9ce50bd
Merge remote-tracking branch 'upstream/master'
surovenko Aug 18, 2021
8f7f147
Merge remote-tracking branch 'upstream/master'
surovenko Aug 19, 2021
d1e96ff
Merge branch 'master' into zeta_ssp_bid_adapter_video_support
surovenko Aug 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
asurovenko-zeta marked this conversation as resolved.
Show resolved Hide resolved
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;
});
});