-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8d46001
Prebid 1.0 compliant bidder adapter
tzafrirb f3b3aea
PlacementId and hbId support display test banner
tzafrirb ca97ef3
Remove aliases
tzafrirb b26570f
remove check for aliases, breaks build
tzafrirb f130123
Add bid response test with mandatory params
tzafrirb 582787a
change #1742 (https://github.com/prebid/Prebid.js/issues/1742): rathe…
tzafrirb 3407256
Merge remote-tracking branch 'upstream/master'
tzafrirb d8b4d20
replace describe with it
tzafrirb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,121 @@ | ||
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, | ||
|
||
/** | ||
* 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.body && response.body.bids) { | ||
response.body.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); | ||
}); | ||
|
||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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: 'e69148e0ba6c4c07977dc2daae5e1577', | ||
hbid: '1f5b2c10e66e419580bd943b9af692ab', | ||
floorPrice: 0.5 | ||
} | ||
}] | ||
}]; | ||
``` | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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