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

VIS.X: add instream video support #6687

Merged
merged 6 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
132 changes: 117 additions & 15 deletions modules/visxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { INSTREAM as VIDEO_INSTREAM } from '../src/video.js';
const { parseSizesInput, getKeys, logError, deepAccess } = utils;
const BIDDER_CODE = 'visx';
const BASE_URL = 'https://t.visx.net';
const ENDPOINT_URL = BASE_URL + '/hb';
Expand All @@ -21,12 +24,21 @@ const LOG_ERROR_MESS = {
hasEmptySeatbidArray: 'Response has empty seatbid array',
hasNoArrayOfBids: 'Seatbid from response has no array of bid objects - ',
notAllowedCurrency: 'Currency is not supported - ',
currencyMismatch: 'Currency from the request is not match currency from the response - '
currencyMismatch: 'Currency from the request is not match currency from the response - ',
onlyVideoInstream: `Only video ${VIDEO_INSTREAM} supported`,
videoMissing: 'Bid request videoType property is missing - '
};
const currencyWhiteList = ['EUR', 'USD', 'GBP', 'PLN'];
const RE_EMPTY_OR_ONLY_COMMAS = /^,*$/;
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function(bid) {
if (_isVideoBid(bid)) {
if (!_isValidVideoBid(bid)) {
return false;
}
}
return !!bid.params.uid;
},
buildRequests: function(validBidRequests, bidderRequest) {
Expand All @@ -42,9 +54,10 @@ export const spec = {
let reqId;
let payloadSchain;
let payloadUserId;
const videoTypes = _initVideoTypes(bids);

if (currencyWhiteList.indexOf(currency) === -1) {
utils.logError(LOG_ERROR_MESS.notAllowedCurrency + currency);
logError(LOG_ERROR_MESS.notAllowedCurrency + currency);
return;
}

Expand All @@ -58,7 +71,7 @@ export const spec = {
if (!payloadUserId && userId) {
payloadUserId = userId;
}
const sizesId = utils.parseSizesInput(bid.sizes);
const sizesId = parseSizesInput(bid.sizes);

if (!slotsMapByUid[uid]) {
slotsMapByUid[uid] = {};
Expand Down Expand Up @@ -89,11 +102,12 @@ export const spec = {
const payload = {
pt: 'net',
auids: auids.join(','),
sizes: utils.getKeys(sizeMap).join(','),
sizes: getKeys(sizeMap).join(','),
r: reqId,
cur: currency,
wrapperType: 'Prebid_js',
wrapperVersion: '$prebid.version$'
wrapperVersion: '$prebid.version$',
...videoTypes
};

if (payloadSchain) {
Expand Down Expand Up @@ -155,7 +169,7 @@ export const spec = {
_addBidResponse(serverBid, bidsMap, currency, bidResponses);
});
}
if (errorMessage) utils.logError(errorMessage);
if (errorMessage) logError(errorMessage);
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
Expand Down Expand Up @@ -191,11 +205,11 @@ export const spec = {

function _getBidFromResponse(respItem) {
if (!respItem) {
utils.logError(LOG_ERROR_MESS.emptySeatbid);
logError(LOG_ERROR_MESS.emptySeatbid);
} else if (!respItem.bid) {
utils.logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem));
logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem));
} else if (!respItem.bid[0]) {
utils.logError(LOG_ERROR_MESS.noBid);
logError(LOG_ERROR_MESS.noBid);
}
return respItem && respItem.bid && respItem.bid[0];
}
Expand All @@ -217,7 +231,7 @@ function _addBidResponse(serverBid, bidsMap, currency, bidResponses, bidsWithout
const slot = awaitingBids[sizeId][0];

const bid = slot.bids.shift();
bidResponses.push({
const bidResponse = {
requestId: bid.bidId,
cpm: serverBid.price,
width: serverBid.w,
Expand All @@ -226,9 +240,17 @@ function _addBidResponse(serverBid, bidsMap, currency, bidResponses, bidsWithout
currency: reqCurrency,
netRevenue: true,
ttl: TIME_TO_LIVE,
ad: serverBid.adm,
dealId: serverBid.dealid
});
};

if (!_isVideoBid(bid)) {
bidResponse.ad = serverBid.adm;
} else {
bidResponse.vastXml = serverBid.adm;
bidResponse.mediaType = 'video';
}

bidResponses.push(bidResponse);

if (!slot.bids.length) {
slot.parents.forEach(({parent, key, uid}) => {
Expand All @@ -238,7 +260,7 @@ function _addBidResponse(serverBid, bidsMap, currency, bidResponses, bidsWithout
}
if (!parent[key].length) {
delete parent[key];
if (!utils.getKeys(parent).length) {
if (!getKeys(parent).length) {
delete bidsMap[uid];
}
}
Expand All @@ -253,8 +275,88 @@ function _addBidResponse(serverBid, bidsMap, currency, bidResponses, bidsWithout
}
}
if (errorMessage) {
utils.logError(errorMessage);
logError(errorMessage);
}
}

function _isVideoBid(bid) {
return bid.mediaType === VIDEO || deepAccess(bid, 'mediaTypes.video');
}

function _isValidVideoBid(bid) {
let result = true;
const videoMediaType = deepAccess(bid, 'mediaTypes.video');
if (videoMediaType.context !== VIDEO_INSTREAM) {
logError(LOG_ERROR_MESS.onlyVideoInstream)
result = false;
}
if (!(videoMediaType.playerSize && parseSizesInput(deepAccess(videoMediaType, 'playerSize', [])))) {
logError(LOG_ERROR_MESS.videoMissing + 'playerSize');
result = false;
}
if (!videoMediaType.mimes) {
logError(LOG_ERROR_MESS.videoMissing + 'mimes');
result = false;
}
if (!videoMediaType.protocols) {
logError(LOG_ERROR_MESS.videoMissing + 'protocols');
result = false;
}
return result;
}

function _initVideoTypes(bids) {
const result = {};
let _playerSize = [];
let _protocols = [];
let _api = [];
let _mimes = [];
let _minduration = [];
let _maxduration = [];
let _skip = [];
if (bids && bids.length) {
bids.forEach(function (bid) {
const mediaTypes = deepAccess(bid, 'mediaTypes.video', {});
_playerSize.push(parseSizesInput(deepAccess(mediaTypes, 'playerSize', [])).join('|'));
_protocols.push(deepAccess(mediaTypes, 'protocols', []).join('|'));
_api.push(deepAccess(mediaTypes, 'api', []).join('|'));
_mimes.push(deepAccess(mediaTypes, 'mimes', []).join('|'));
_minduration.push(deepAccess(mediaTypes, 'minduration', null));
_maxduration.push(deepAccess(mediaTypes, 'maxduration', null));
_skip.push(deepAccess(mediaTypes, 'skip', null));
});
}
_playerSize = _playerSize.join(',');
_protocols = _protocols.join(',');
_api = _api.join(',');
_mimes = _mimes.join(',');
_minduration = _minduration.join(',');
_maxduration = _maxduration.join(',');
_skip = _skip.join(',');

if (!RE_EMPTY_OR_ONLY_COMMAS.test(_playerSize)) {
result.playerSize = _playerSize;
}
if (!RE_EMPTY_OR_ONLY_COMMAS.test(_protocols)) {
result.protocols = _protocols;
}
if (!RE_EMPTY_OR_ONLY_COMMAS.test(_api)) {
result.api = _api;
}
if (!RE_EMPTY_OR_ONLY_COMMAS.test(_mimes)) {
result.mimes = _mimes;
}
if (!RE_EMPTY_OR_ONLY_COMMAS.test(_minduration)) {
result.minduration = _minduration;
}
if (!RE_EMPTY_OR_ONLY_COMMAS.test(_maxduration)) {
result.maxduration = _maxduration;
}
if (!RE_EMPTY_OR_ONLY_COMMAS.test(_skip)) {
result.skip = _skip;
}

return result;
}

registerBidder(spec);
86 changes: 57 additions & 29 deletions modules/visxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,61 @@ Maintainer: service@yoc.com
Module that connects to YOC VIS.X® demand source to fetch bids.

# Test Parameters
```javascript
var adUnits = [
// YOC Mystery Ad adUnit
{
code: 'yma-test-div',
mediaTypes: {
banner: {
sizes: [[1, 1]]
}
},
bids: [
{
bidder: 'visx',
params: {
uid: '903535'
}
}
]
},
// YOC Understitial Ad adUnit
{
code: 'yua-test-div',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: 'visx',
params: {
uid: '903536'
}
}
]
},
// YOC In-stream adUnit
{
code: 'instream-test-div',
mediaTypes: {
video: {
context: 'instream',
playerSize: [400, 300],
mimes: ['video/mp4'],
protocols: [3, 6]
},
},
bids: [
{
bidder: 'visx',
params: {
uid: '921068'
}
}
]
}
];
```
var adUnits = [
// YOC Mystery Ad adUnit
{
code: 'yma-test-div',
sizes: [[1, 1]],
bids: [
{
bidder: 'visx',
params: {
uid: '903535'
}
}
]
},
// YOC Understitial Ad adUnit
{
code: 'yua-test-div',
sizes: [[300, 250]],
bids: [
{
bidder: 'visx',
params: {
uid: '903536'
}
}
]
}
];
```
Loading