Skip to content

Commit

Permalink
Added VIS.X Bidder Adapter (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Wojda authored and snapwich committed Apr 16, 2018
1 parent 825ab83 commit fa6e221
Show file tree
Hide file tree
Showing 3 changed files with 539 additions and 0 deletions.
140 changes: 140 additions & 0 deletions modules/visxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import { config } from 'src/config';
const BIDDER_CODE = 'visx';
const ENDPOINT_URL = '//t.visx.net/hb';
const TIME_TO_LIVE = 360;
const DEFAULT_CUR = 'EUR';
const ADAPTER_SYNC_URL = '//t.visx.net/push_sync';
const LOG_ERROR_MESS = {
noAuid: 'Bid from response has no auid parameter - ',
noAdm: 'Bid from response has no adm parameter - ',
noBid: 'Array of bid objects is empty',
noPlacementCode: 'Can\'t find in requested bids the bid with auid - ',
emptyUids: 'Uids should not be empty',
emptySeatbid: 'Seatbid array from response has an empty item',
emptyResponse: 'Response is empty',
hasEmptySeatbidArray: 'Response has empty seatbid array',
hasNoArrayOfBids: 'Seatbid from response has no array of bid objects - '
};
export const spec = {
code: BIDDER_CODE,
isBidRequestValid: function(bid) {
return !!bid.params.uid;
},
buildRequests: function(validBidRequests) {
const auids = [];
const bidsMap = {};
const bids = validBidRequests || [];
const currency =
config.getConfig(`currency.bidderCurrencyDefault.${BIDDER_CODE}`) ||
config.getConfig('currency.adServerCurrency') ||
DEFAULT_CUR;
let priceType = 'net';
let reqId;

bids.forEach(bid => {
if (bid.params.priceType === 'gross') {
priceType = 'gross';
}
if (!bidsMap[bid.params.uid]) {
bidsMap[bid.params.uid] = [bid];
auids.push(bid.params.uid);
} else {
bidsMap[bid.params.uid].push(bid);
}
reqId = bid.bidderRequestId;
});

const payload = {
u: utils.getTopWindowUrl(),
pt: priceType,
auids: auids.join(','),
test: 1,
r: reqId,
cur: currency,
};

return {
method: 'GET',
url: ENDPOINT_URL,
data: payload,
bidsMap: bidsMap,
};
},
interpretResponse: function(serverResponse, bidRequest) {
serverResponse = serverResponse && serverResponse.body;
const bidResponses = [];
const bidsMap = bidRequest.bidsMap;
const priceType = bidRequest.data.pt;
const currency = bidRequest.data.cur;

let errorMessage;

if (!serverResponse) errorMessage = LOG_ERROR_MESS.emptyResponse;
else if (serverResponse.seatbid && !serverResponse.seatbid.length) {
errorMessage = LOG_ERROR_MESS.hasEmptySeatbidArray;
}

if (!errorMessage && serverResponse.seatbid) {
serverResponse.seatbid.forEach(respItem => {
_addBidResponse(_getBidFromResponse(respItem), bidsMap, priceType, currency, bidResponses);
});
}
if (errorMessage) utils.logError(errorMessage);
return bidResponses;
},
getUserSyncs: function(syncOptions) {
if (syncOptions.pixelEnabled) {
return [{
type: 'image',
url: ADAPTER_SYNC_URL
}];
}
}
};

function _getBidFromResponse(respItem) {
if (!respItem) {
utils.logError(LOG_ERROR_MESS.emptySeatbid);
} else if (!respItem.bid) {
utils.logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem));
} else if (!respItem.bid[0]) {
utils.logError(LOG_ERROR_MESS.noBid);
}
return respItem && respItem.bid && respItem.bid[0];
}

function _addBidResponse(serverBid, bidsMap, priceType, currency, bidResponses) {
if (!serverBid) return;
let errorMessage;
if (!serverBid.auid) errorMessage = LOG_ERROR_MESS.noAuid + JSON.stringify(serverBid);
if (!serverBid.adm) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid);
else {
const awaitingBids = bidsMap[serverBid.auid];
if (awaitingBids) {
awaitingBids.forEach(bid => {
const bidResponse = {
requestId: bid.bidId,
cpm: serverBid.price,
width: serverBid.w,
height: serverBid.h,
creativeId: serverBid.auid,
currency: currency || DEFAULT_CUR,
netRevenue: priceType !== 'gross',
ttl: TIME_TO_LIVE,
ad: serverBid.adm,
dealId: serverBid.dealid
};
bidResponses.push(bidResponse);
});
} else {
errorMessage = LOG_ERROR_MESS.noPlacementCode + serverBid.auid;
}
}
if (errorMessage) {
utils.logError(errorMessage);
}
}

registerBidder(spec);
43 changes: 43 additions & 0 deletions modules/visxBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Overview

```
Module Name: VIS.X Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Module that connects to VIS.X demand source to fetch bids.

# Test Parameters
```
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

0 comments on commit fa6e221

Please sign in to comment.