-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(krux): add Krux Link adapter (#384)
- Loading branch information
Seth Yates
authored and
protonate
committed
Jun 15, 2016
1 parent
d5b0e4f
commit c951eac
Showing
3 changed files
with
106 additions
and
24 deletions.
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
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"aol", | ||
"appnexus", | ||
"indexExchange", | ||
"kruxlink", | ||
"openx", | ||
"pubmatic", | ||
"pulsepoint", | ||
|
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,79 @@ | ||
var bidfactory = require('../bidfactory.js'); | ||
var bidmanager = require('../bidmanager.js'); | ||
var adloader = require('../adloader.js'); | ||
|
||
function _qs(key, value) { | ||
return encodeURIComponent(key) + '=' + encodeURIComponent(value); | ||
} | ||
|
||
function _makeBidResponse(placementCode, bid) { | ||
var bidResponse = bidfactory.createBid(bid !== undefined ? 1 : 2); | ||
bidResponse.bidderCode = 'kruxlink'; | ||
if (bid !== undefined) { | ||
bidResponse.cpm = bid.price; | ||
bidResponse.ad = bid.adm; | ||
bidResponse.width = bid.w; | ||
bidResponse.height = bid.h; | ||
} | ||
bidmanager.addBidResponse(placementCode, bidResponse); | ||
} | ||
|
||
function _makeCallback(id, placements) { | ||
var callback = '_kruxlink_' + id; | ||
pbjs[callback] = function(response) { | ||
// Clean up our callback | ||
delete pbjs[callback]; | ||
|
||
// Add in the bid respones | ||
for (var i = 0; i < response.seatbid.length; i++) { | ||
var seatbid = response.seatbid[i]; | ||
for (var j = 0; j < seatbid.bid.length; j++) { | ||
var bid = seatbid.bid[j]; | ||
_makeBidResponse(placements[bid.impid], bid); | ||
delete placements[bid.impid]; | ||
} | ||
} | ||
|
||
// Add any no-bids remaining | ||
for (var placementCode in placements) { | ||
if (placements.hasOwnProperty(placementCode)) { | ||
_makeBidResponse(placementCode); | ||
} | ||
} | ||
}; | ||
|
||
return 'pbjs.' + callback; | ||
} | ||
|
||
function _callBids(params) { | ||
var impids = []; | ||
var placements = {}; | ||
|
||
var bids = params.bids || []; | ||
for (var i = 0; i < bids.length; i++) { | ||
var bidRequest = bids[i]; | ||
var bidRequestParams = bidRequest.params || {}; | ||
var impid = bidRequestParams.impid; | ||
placements[impid] = bidRequest.placementCode; | ||
|
||
impids.push(impid); | ||
} | ||
|
||
var callback = _makeCallback(params.bidderRequestId, placements); | ||
var qs = [ | ||
_qs('id', params.bidderRequestId), | ||
_qs('u', window.location.href), | ||
_qs('impid', impids.join(',')), | ||
_qs('calltype', 'pbd'), | ||
_qs('callback', callback) | ||
]; | ||
var url = 'https://link.krxd.net/hb?' + qs.join('&'); | ||
|
||
adloader.loadScript(url); | ||
} | ||
|
||
module.exports = function KruxAdapter() { | ||
return { | ||
callBids: _callBids | ||
}; | ||
}; |