-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow rubicon adapter to register individual responses from fastlane #2
Changes from all commits
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 |
---|---|---|
|
@@ -63,11 +63,11 @@ var RubiconAdapter = function RubiconAdapter() { | |
/** | ||
* Create an error bid | ||
* @param {String} placement - the adunit path | ||
* @param {Object} response - the (error) response from fastlane | ||
* @param {Object} slot - the (error) response from fastlane | ||
* @return {Bid} a bid, for prebid | ||
*/ | ||
function _errorBid(response, ads) { | ||
var bidResponse = bidfactory.createBid(2, response.bid); | ||
function _errorBid(slot, ads) { | ||
var bidResponse = bidfactory.createBid(2, slot.bid); | ||
bidResponse.bidderCode = RUBICON_BIDDER_CODE; | ||
|
||
// use the raw ads as the 'error' | ||
|
@@ -107,70 +107,68 @@ var RubiconAdapter = function RubiconAdapter() { | |
} | ||
|
||
/** | ||
* Create (successful) bids for a unit, | ||
* Create (successful) bids for a slot, | ||
* based on the given response | ||
* @param {String} placement placement code/unit path | ||
* @param {Object} response the response from rubicon | ||
* @return {Bid} a bid objectj | ||
* @param {Object} slot the slot from rubicon | ||
* @param {Object} ads the raw responses | ||
*/ | ||
function _makeBids(response, ads) { | ||
function _makeBids(slot, ads) { | ||
|
||
// if there are multiple ads, sort by CPM | ||
ads = ads.sort(_adCpmSort); | ||
|
||
var bidResponses = []; | ||
|
||
ads.forEach(function(ad) { | ||
|
||
var bidResponse, | ||
size = ad.dimensions; | ||
|
||
if (!size) { | ||
// this really shouldn't happen | ||
utils.logError('no dimensions given', RUBICON_BIDDER_CODE, ad); | ||
bidResponse = _errorBid(response, ads); | ||
} else { | ||
bidResponse = bidfactory.createBid(1, response.bid); | ||
if (!ads || ads.length === 0) { | ||
|
||
bidResponse.bidderCode = RUBICON_BIDDER_CODE; | ||
bidResponse.cpm = ad.cpm; | ||
bidmanager.addBidResponse( | ||
slot.getElementId(), | ||
_errorBid(slot, ads) | ||
); | ||
|
||
// the element id is what the iframe will use to render | ||
// itself using the rubicontag.renderCreative API | ||
bidResponse.ad = _creative(response.getElementId(), size); | ||
bidResponse.width = size[0]; | ||
bidResponse.height = size[1]; | ||
} else { | ||
|
||
// DealId | ||
if (ad.deal) { | ||
bidResponse.dealId = ad.deal; | ||
} | ||
} | ||
// if there are multiple ads, sort by CPM | ||
ads = ads.sort(_adCpmSort); | ||
|
||
bidResponses.push(bidResponse); | ||
ads.forEach(function (ad) { | ||
_makeBid(slot, ad); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
return bidResponses; | ||
} | ||
|
||
/** | ||
* Add success/error bids based | ||
* on the response from rubicon | ||
* @param {Object} response -- AJAX response from fastlane | ||
* Create (successful) bid for a slot size, | ||
* based on the given response | ||
* @param {Object} slot the slot from rubicon | ||
* @param {Object} ad a raw response | ||
*/ | ||
function _addBids(response, ads) { | ||
// get the bid for the placement code | ||
var bids; | ||
if (!ads || ads.length === 0) { | ||
bids = [ _errorBid(response, ads) ]; | ||
function _makeBid(slot, ad) { | ||
|
||
var bidResponse, | ||
size = ad.dimensions; | ||
|
||
if (!size) { | ||
// this really shouldn't happen | ||
utils.logError('no dimensions given', RUBICON_BIDDER_CODE, ad); | ||
bidResponse = _errorBid(slot, ad); | ||
} else { | ||
bids = _makeBids(response, ads); | ||
bidResponse = bidfactory.createBid(1, slot.bid); | ||
|
||
bidResponse.bidderCode = RUBICON_BIDDER_CODE; | ||
bidResponse.cpm = ad.cpm; | ||
|
||
// the element id is what the iframe will use to render | ||
// itself using the rubicontag.renderCreative API | ||
bidResponse.ad = _creative(slot.getElementId(), size); | ||
bidResponse.width = size[0]; | ||
bidResponse.height = size[1]; | ||
|
||
// DealId | ||
if (ad.deal) { | ||
bidResponse.dealId = ad.deal; | ||
} | ||
} | ||
|
||
bids.forEach(function(bid) { | ||
bidmanager.addBidResponse(response.getElementId(), bid); | ||
}); | ||
bidmanager.addBidResponse(slot.getElementId(), bidResponse); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -286,10 +284,32 @@ var RubiconAdapter = function RubiconAdapter() { | |
utils.logMessage('Rubicon Project bidding complete: ' + ((new Date).getTime() - _bidStart)); | ||
|
||
utils._each(slots, function (slot) { | ||
_addBids(slot, slot.getRawResponses()); | ||
_makeBids(slot, slot.getRawResponses()); | ||
}); | ||
} | ||
|
||
|
||
var _cb; | ||
var _eventAvailable; | ||
/** | ||
* Used to attach (and switch out) callback for listening to rubicon bid events | ||
* Rubicon | ||
* @param {Function} cb Callback to register with event handler | ||
* @return {Boolean} whether we can handle the event or not | ||
*/ | ||
function _handleBidEvent(cb) { | ||
_cb = cb; | ||
if(_eventAvailable) { | ||
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. if( here and if ( two lines below. Either is find, but consistency would be best. Find replace all occurences 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. 👍 |
||
return true; | ||
} | ||
if (_eventAvailable === false) { | ||
return false; | ||
} | ||
return _eventAvailable = window.rubicontag.addEventListener('FL_TIER_MAPPED', params => { | ||
_cb(params); | ||
}) | ||
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. forgot ; ? 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. 👍 |
||
} | ||
|
||
/** | ||
* Request the specified bids from | ||
* Rubicon | ||
|
@@ -325,9 +345,23 @@ var RubiconAdapter = function RubiconAdapter() { | |
slots: slots, | ||
timeout: bidderRequest.timeout - (Date.now() - bidderRequest.auctionStart - TIMEOUT_BUFFER) | ||
}; | ||
var callback = function () { | ||
_bidsReady(slots); | ||
}; | ||
var callback = function noop() {}; | ||
|
||
if(!_handleBidEvent(params => { | ||
|
||
var slot = slots.find(slot => slot.getElementId() === params.elementId); | ||
var ad = slot.getRawResponseBySizeId(params.sizeId); | ||
var time = ((new Date).getTime() - _bidStart); | ||
|
||
utils.logMessage(`Rubicon Project bid back for "${params.elementId}" size ${params.sizeId} at: ${time}`); | ||
|
||
_makeBid(slot, ad); | ||
|
||
})) { | ||
callback = () => { | ||
_bidsReady(slots); | ||
} | ||
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. Maybe im unclear on ECMA 6 syntax. Are ; absent for assignments? 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. technically in Javascript semi-colons are not needed almost everywhere, but I'm generally a semi-colon user, just forgot here. 👍 |
||
} | ||
|
||
window.rubicontag.setIntegration('$$PREBID_GLOBAL$$'); | ||
window.rubicontag.run(callback, parameters); | ||
|
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.
_createBid may be an option here
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 function just came from pulling singular functionality out of
_makeBids
which I didn't name and still exists. I could rename them both, but for now I think I'll just leave it.