Skip to content

Commit

Permalink
sekindoUM for prebid1.0 (#1777)
Browse files Browse the repository at this point in the history
* sekindoUMBidAdapter for prebid.js 1.0

* sekindoUM for prebid 1.0
  • Loading branch information
nissSK authored and matthewlane committed Dec 4, 2017
1 parent ef4ffdb commit f93c2dd
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 147 deletions.
206 changes: 115 additions & 91 deletions modules/sekindoUMBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,115 @@
import { getBidRequest } from 'src/utils.js';
import { config } from 'src/config';

var CONSTANTS = require('src/constants.json');
var utils = require('src/utils.js');
var bidfactory = require('src/bidfactory.js');
var bidmanager = require('src/bidmanager.js');
var adloader = require('src/adloader.js');
var adaptermanager = require('src/adaptermanager');

function SekindoUMAdapter() {
function _callBids(params) {
var bids = params.bids;
var bidsCount = bids.length;

var pubUrl = null;
if (parent !== window) { pubUrl = document.referrer; } else { pubUrl = window.location.href; }

for (var i = 0; i < bidsCount; i++) {
var bidReqeust = bids[i];
var callbackId = bidReqeust.bidId;
_requestBids(bidReqeust, callbackId, pubUrl);
// store a reference to the bidRequest from the callback id
// bidmanager.pbCallbackMap[callbackId] = bidReqeust;
}
}

$$PREBID_GLOBAL$$.sekindoCB = function(callbackId, response) {
var bidObj = getBidRequest(callbackId);
if (typeof (response) !== 'undefined' && typeof (response.cpm) !== 'undefined') {
var bid = [];
if (bidObj) {
var bidCode = bidObj.bidder;
var placementCode = bidObj.placementCode;

if (response.cpm !== undefined && response.cpm > 0) {
bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD);
bid.callback_uid = callbackId;
bid.bidderCode = bidCode;
bid.creative_id = response.adId;
bid.cpm = parseFloat(response.cpm);
bid.ad = response.ad;
bid.width = response.width;
bid.height = response.height;

bidmanager.addBidResponse(placementCode, bid);
} else {
bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID);
bid.callback_uid = callbackId;
bid.bidderCode = bidCode;
bidmanager.addBidResponse(placementCode, bid);
}
}
} else {
if (bidObj) {
utils.logMessage('No prebid response for placement ' + bidObj.placementCode);
} else {
utils.logMessage('sekindoUM callback general error');
}
}
};

function _requestBids(bid, callbackId, pubUrl) {
// determine tag params
var spaceId = utils.getBidIdParameter('spaceId', bid.params);
var subId = utils.getBidIdParameter('subId', bid.params);
var bidfloor = utils.getBidIdParameter('bidfloor', bid.params);
var protocol = (document.location.protocol === 'https:' ? 's' : '');
var scriptSrc = 'http' + protocol + '://hb.sekindo.com/live/liveView.php?';

scriptSrc = utils.tryAppendQueryString(scriptSrc, 's', spaceId);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'subId', subId);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'pubUrl', pubUrl);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbcb', callbackId);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbver', '3');
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbobj', '$$PREBID_GLOBAL$$');
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'dcpmflr', bidfloor);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbto', config.getConfig('bidderTimeout'));
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'protocol', protocol);

adloader.loadScript(scriptSrc);
}

return {
callBids: _callBids
};
}

adaptermanager.registerBidAdapter(new SekindoUMAdapter(), 'sekindoUM');

module.exports = SekindoUMAdapter;
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
export const spec = {
code: 'sekindoUM',
supportedMediaTypes: ['video'],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
if (bid.mediaType == 'video' || (typeof bid.mediaTypes == 'object' && typeof bid.mediaTypes.video == 'object')) {
if (typeof bid.params.video != 'object' || typeof bid.params.video.playerWidth == 'undefined' || typeof bid.params.video.playerHeight == 'undefined') {
return false;
}
}
return !!(bid.params.spaceId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {
var pubUrl = null;
if (parent !== window) {
pubUrl = document.referrer;
} else {
pubUrl = window.location.href;
}

return validBidRequests.map(bidRequest => {
var subId = utils.getBidIdParameter('subId', bidRequest.params);
var spaceId = utils.getBidIdParameter('spaceId', bidRequest.params);
var bidfloor = utils.getBidIdParameter('bidfloor', bidRequest.params);
var protocol = (document.location.protocol === 'https:' ? 's' : '');
var queryString = '';

queryString = utils.tryAppendQueryString(queryString, 's', spaceId);
queryString = utils.tryAppendQueryString(queryString, 'subId', subId);
queryString = utils.tryAppendQueryString(queryString, 'pubUrl', pubUrl);
queryString = utils.tryAppendQueryString(queryString, 'hbTId', bidRequest.transactionId);
queryString = utils.tryAppendQueryString(queryString, 'hbBidId', bidRequest.bidId);
queryString = utils.tryAppendQueryString(queryString, 'hbver', '4');
queryString = utils.tryAppendQueryString(queryString, 'hbcb', '1');/// legasy
queryString = utils.tryAppendQueryString(queryString, 'dcpmflr', bidfloor);
queryString = utils.tryAppendQueryString(queryString, 'protocol', protocol);
if (bidRequest.mediaType === 'video' || (typeof bidRequest.mediaTypes == 'object' && typeof bidRequest.mediaTypes.video == 'object')) {
queryString = utils.tryAppendQueryString(queryString, 'x', bidRequest.params.playerWidth);
queryString = utils.tryAppendQueryString(queryString, 'y', bidRequest.params.playerHeight);
if (typeof vid_vastType != 'undefined') {
queryString = utils.tryAppendQueryString(queryString, 'vid_vastType', bidRequest.params.vid_vastType);
}
if (typeof bidRequest.mediaTypes == 'object' && typeof bidRequest.mediaTypes.video == 'object' && typeof bidRequest.mediaTypes.video.context == 'string') {
queryString = utils.tryAppendQueryString(queryString, 'vid_context', bidRequest.mediaTypes.video.context);
}
}

var endpointUrl = 'http' + protocol + '://hb.sekindo.com/live/liveView.php';

return {
method: 'GET',
url: endpointUrl,
data: queryString,
};
});
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
if (typeof serverResponse !== 'object') {
return [];
}

let bidResponses = [];
var bidResponse = {
requestId: serverResponse.body.id,
bidderCode: spec.code,
cpm: serverResponse.body.cpm,
width: serverResponse.body.width,
height: serverResponse.body.height,
creativeId: serverResponse.body.creativeId,
currency: serverResponse.body.currency,
netRevenue: serverResponse.body.netRevenue,
ttl: serverResponse.body.ttl
};
if (bidRequest.mediaType == 'video') {
if (typeof serverResponse.body.vastUrl != 'undefined') {
bidResponse.vastUrl = serverResponse.body.vastUrl;
} else {
bidResponse.vastXml = serverResponse.body.vastXml;
}
} else {
bidResponse.ad = serverResponse.body.ad;
}

bidResponses.push(bidResponse);
return bidResponses;
},
getUserSyncs: function(syncOptions) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: 'ADAPTER_SYNC_URL'
}];
}
}
}
registerBidder(spec);
41 changes: 41 additions & 0 deletions modules/sekindoUMBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Overview

**Module Name**: sekindoUM Bidder Adapter
**Module Type**: Bidder Adapter
**Maintainer**: nissime@sekindo.com

# Description

Connects to Sekindo (part of UM) demand source to fetch bids.
Banner, Outstream and Native formats are supported.


# Test Parameters
```
var adUnits = [{
code: 'banner-ad-div',
sizes: [[300, 250]],
bids: [{
bidder: 'sekindoUM',
params: {
spaceId: 14071
}
}]
},
{
code: 'video-ad-div',
sizes: [[640, 480]],
bids: [{
bidder: 'sekindoUM',
params: {
spaceId: 87812,
video:{
playerWidth:640,
playerHeight:480,
vid_vastType: 5 //optional
}
}
}]
}
];
```
Loading

0 comments on commit f93c2dd

Please sign in to comment.