-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Prebid 1.0 compliant Komoona bidder adapter #1743
Changes from 1 commit
8d46001
f3b3aea
ca97ef3
b26570f
f130123
582787a
3407256
d8b4d20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,123 @@ | ||
import Adapter from 'src/adapter'; | ||
import bidfactory from 'src/bidfactory'; | ||
import bidmanager from 'src/bidmanager'; | ||
import * as utils from 'src/utils'; | ||
import { ajax } from 'src/ajax'; | ||
import { STATUS } from 'src/constants'; | ||
import adaptermanager from 'src/adaptermanager'; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'komoona'; | ||
const ENDPOINT = '//bidder.komoona.com/v1/GetSBids'; | ||
const USYNCURL = '//s.komoona.com/sync/usync.html'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
|
||
aliases: ['komoona'], | ||
|
||
/** | ||
* Determines whether or not the given bid request is valid. Valid bid request must have placementId and hbid | ||
* | ||
* @param {BidRequest} bid The bid params to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: bid => { | ||
return !!(bid && bid.params && bid.params.placementId && bid.params.hbid); | ||
}, | ||
/** | ||
* 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: validBidRequests => { | ||
const tags = validBidRequests.map(bid => { | ||
// map each bid id to bid object to retrieve adUnit code in callback | ||
let tag = { | ||
uuid: bid.bidId, | ||
sizes: bid.sizes, | ||
trid: bid.transactionId, | ||
hbid: bid.params.hbid, | ||
placementid: bid.params.placementId | ||
}; | ||
|
||
// add floor price if specified (not mandatory) | ||
if (bid.params.floorPrice) { | ||
tag.floorprice = bid.params.floorPrice; | ||
} | ||
|
||
function KomoonaAdapter() { | ||
let baseAdapter = new Adapter('komoona'); | ||
let bidRequests = {}; | ||
|
||
/* Prebid executes this function when the page asks to send out bid requests */ | ||
baseAdapter.callBids = function(bidRequest) { | ||
const bids = bidRequest.bids || []; | ||
const tags = bids | ||
.filter(bid => valid(bid)) | ||
.map(bid => { | ||
// map request id to bid object to retrieve adUnit code in callback | ||
bidRequests[bid.bidId] = bid; | ||
|
||
let tag = {}; | ||
tag.sizes = bid.sizes; | ||
tag.uuid = bid.bidId; | ||
tag.placementid = bid.params.placementId; | ||
tag.hbid = bid.params.hbid; | ||
return tag; | ||
}); | ||
|
||
return tag; | ||
}); | ||
// Komoona server config | ||
const time = new Date().getTime(); | ||
const kbConf = { | ||
ts_as: time, | ||
hb_placements: [], | ||
hb_placement_bidids: {}, | ||
hb_floors: {}, | ||
cb: _generateCb(time), | ||
tz: new Date().getTimezoneOffset(), | ||
}; | ||
|
||
validBidRequests.forEach(bid => { | ||
kbConf.hdbdid = kbConf.hdbdid || bid.params.hbid; | ||
kbConf.encode_bid = kbConf.encode_bid || bid.params.encode_bid; | ||
kbConf.hb_placement_bidids[bid.params.placementId] = bid.bidId; | ||
if (bid.params.floorPrice) { | ||
kbConf.hb_floors[bid.params.placementId] = bid.params.floorPrice; | ||
} | ||
kbConf.hb_placements.push(bid.params.placementId); | ||
}); | ||
|
||
let payload = {}; | ||
if (!utils.isEmpty(tags)) { | ||
const payload = JSON.stringify({bids: [...tags]}); | ||
|
||
ajax(ENDPOINT, handleResponse, payload, { | ||
contentType: 'text/plain', | ||
withCredentials: true | ||
}); | ||
payload = { bids: [...tags], kbConf: kbConf }; | ||
} | ||
}; | ||
|
||
/* Notify Prebid of bid responses so bids can get in the auction */ | ||
function handleResponse(response) { | ||
let parsed; | ||
|
||
return { | ||
method: 'POST', | ||
url: ENDPOINT, | ||
data: JSON.stringify(payload) | ||
}; | ||
}, | ||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {*} response A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: (response, request) => { | ||
const bidResponses = []; | ||
try { | ||
parsed = JSON.parse(response); | ||
} catch (error) { | ||
utils.logError(error); | ||
} | ||
|
||
if (!parsed || parsed.error) { | ||
let errorMessage = `in response for ${baseAdapter.getBidderCode()} adapter`; | ||
if (parsed && parsed.error) { errorMessage += `: ${parsed.error}`; } | ||
utils.logError(errorMessage); | ||
|
||
// signal this response is complete | ||
Object.keys(bidRequests) | ||
.map(bidId => bidRequests[bidId].placementCode) | ||
.forEach(placementCode => { | ||
bidmanager.addBidResponse(placementCode, createBid(STATUS.NO_BID)); | ||
if (response.bids) { | ||
response.bids.forEach(bid => { | ||
// The bid ID. Used to tie this bid back to the request. | ||
bid.requestId = bid.uuid; | ||
// The creative payload of the returned bid. | ||
bid.ad = bid.creative; | ||
bidResponses.push(bid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are lots of required params missing from these bids. See: https://github.com/prebid/Prebid.js/pull/1738/files#diff-ac0af2601dcafed83fa9a11b814bf3b5L109 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our md file was updated with correct placement Id and hb Id for test creative (as well as our servers) and now when using placementId and hbId from md file, the hello_world file will always return a creative There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working to fix it, it was added to our servers and now testing it out - will ping once live and fixed |
||
}); | ||
|
||
return; | ||
} | ||
|
||
parsed.bids.forEach(tag => { | ||
let status; | ||
if (tag.cpm > 0 && tag.creative) { | ||
status = STATUS.GOOD; | ||
} else { | ||
status = STATUS.NO_BID; | ||
} | ||
|
||
tag.bidId = tag.uuid; // bidfactory looks for bidId on requested bid | ||
const bid = createBid(status, tag); | ||
const placement = bidRequests[bid.adId].placementCode; | ||
|
||
bidmanager.addBidResponse(placement, bid); | ||
}); | ||
} | ||
|
||
/* Check that a bid has required paramters */ | ||
function valid(bid) { | ||
if (bid.params.placementId && bid.params.hbid) { | ||
return bid; | ||
} else { | ||
utils.logError('bid requires placementId and hbid params'); | ||
} catch (error) { | ||
utils.logError(error); | ||
} | ||
} | ||
|
||
/* Create and return a bid object based on status and tag */ | ||
function createBid(status, tag) { | ||
let bid = bidfactory.createBid(status, tag); | ||
bid.code = baseAdapter.getBidderCode(); | ||
bid.bidderCode = baseAdapter.getBidderCode(); | ||
|
||
if (status === STATUS.GOOD) { | ||
bid.cpm = tag.cpm; | ||
bid.width = tag.width; | ||
bid.height = tag.height; | ||
bid.ad = tag.creative; | ||
return bidResponses; | ||
}, | ||
/** | ||
* Register User Sync. | ||
*/ | ||
getUserSyncs: syncOptions => { | ||
if (syncOptions.iframeEnabled) { | ||
return [{ | ||
type: 'iframe', | ||
url: USYNCURL | ||
}]; | ||
} | ||
|
||
return bid; | ||
} | ||
|
||
return Object.assign(this, { | ||
callBids: baseAdapter.callBids, | ||
setBidderCode: baseAdapter.setBidderCode, | ||
}); | ||
}; | ||
|
||
/** | ||
* Generated cache baster value to be sent to bid server | ||
* @param {*} time current time to use for creating cb. | ||
*/ | ||
function _generateCb(time) { | ||
return Math.floor((time % 65536) + (Math.floor(Math.random() * 65536) * 65536)); | ||
} | ||
|
||
adaptermanager.registerBidAdapter(new KomoonaAdapter(), 'komoona'); | ||
|
||
module.exports = KomoonaAdapter; | ||
registerBidder(spec); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Overview | ||
|
||
**Module Name**: Komoona Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: support@komoona.com | ||
|
||
# Description | ||
|
||
Connects to Komoona demand source to fetch bids. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [{ | ||
code: 'banner-ad-div', | ||
sizes: [[300, 250]], | ||
|
||
// Replace this object to test a new Adapter! | ||
bids: [{ | ||
bidder: 'komoona', | ||
params: { | ||
placementId: '1fee3606cd9b74644d9754b9dc9f6da5', | ||
hbid: '2ac5aea5692a4cfabaf77141c7d87676', | ||
floorPrice: 0.5 | ||
} | ||
}] | ||
}]; | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for adapters which have multiple names... since this is the same as your
BIDDER_CODE
, you can just delete it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed from adapter file, thanks from the comment