-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Update Pollux Adapter to v1.0 #1694
Merged
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a7c0709
Added PolluxNetwork Bid Adapter
hdjvieira a6000c5
Update Pollux domain
hdjvieira 52e1dc8
Export getParameterByName method
hdjvieira f745fe1
Executed changes requested by @jaiminpanchal27 on 2017-08-01
hdjvieira 5f6cbeb
Merge remote-tracking branch 'upstream/master'
hdjvieira 33c5ede
Fixed Eslint errors on commit f745fe1
hdjvieira e41b0a6
Merge remote-tracking branch 'upstream/master'
hdjvieira 34131a6
Executed changes requested on PR#1431 review #54993573
hdjvieira 2967409
Merge remote-tracking branch 'upstream/master'
hdjvieira 1d3ef09
Remove redundant export
matthewlane b5f8786
Merge remote-tracking branch 'upstream/master'
hdjvieira b87a546
Merge remote-tracking branch 'origin/master'
hdjvieira af1bff9
Merge remote-tracking branch 'upstream/master'
hdjvieira 55ca83f
Update Pollux Adapter to v1.0
hdjvieira 2cff78b
Merge remote-tracking branch 'upstream/master'
hdjvieira f2aefa8
Merge branch 'master' into master
hdjvieira 53a4966
Merge branch 'master' into master
hdjvieira 50f59ae
Changes requested on Pollux Adapter pull request #1694 review #74933409
hdjvieira 38ff60a
Merge remote-tracking branch 'upstream/master'
hdjvieira cb8f93d
Changes requested on Pollux Adapter pull request #1694 review #75505070
hdjvieira cc653ac
Fixed breaking changes to serverResponse in interpretResponse method
hdjvieira 0385226
Fix lint errors on push for commit cc653a
hdjvieira File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
---|---|---|
@@ -1,97 +1,115 @@ | ||
import bidfactory from 'src/bidfactory'; | ||
import bidmanager from 'src/bidmanager'; | ||
import * as utils from 'src/utils'; | ||
import adloader from 'src/adloader'; | ||
import adaptermanager from 'src/adaptermanager'; | ||
import { STATUS } from 'src/constants'; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
|
||
// Prebid adapter for Pollux header bidding client | ||
function PolluxBidAdapter() { | ||
function _callBids(params) { | ||
var bidderUrl = (window.location.protocol) + '//adn.plxnt.com/prebid'; | ||
var bids = params.bids || []; | ||
for (var i = 0; i < bids.length; i++) { | ||
var request_obj = {}; | ||
var bid = bids[i]; | ||
// check params | ||
if (bid.params.zone) { | ||
var domain = utils.getParameterByName('domain'); | ||
var tracker2 = utils.getParameterByName('tracker2'); | ||
if (domain) { | ||
request_obj.domain = domain; | ||
} else { | ||
request_obj.domain = window.location.host; | ||
} | ||
if (tracker2) { | ||
request_obj.tracker2 = tracker2; | ||
} | ||
request_obj.zone = bid.params.zone; | ||
} else { | ||
utils.logError('required param "zone" is missing', 'polluxHandler'); | ||
continue; | ||
} | ||
var parsedSizes = utils.parseSizesInput(bid.sizes); | ||
var parsedSizesLength = parsedSizes.length; | ||
if (parsedSizesLength > 0) { | ||
// first value should be "size" | ||
request_obj.size = parsedSizes[0]; | ||
if (parsedSizesLength > 1) { | ||
// any subsequent values should be "promo_sizes" | ||
var promo_sizes = []; | ||
for (var j = 1; j < parsedSizesLength; j++) { | ||
promo_sizes.push(parsedSizes[j]); | ||
} | ||
request_obj.promo_sizes = promo_sizes.join(','); | ||
} | ||
} | ||
// detect urls | ||
request_obj.callback_id = bid.bidId; | ||
// set a different url bidder | ||
if (bid.bidderUrl) { | ||
bidderUrl = bid.bidderUrl; | ||
const BIDDER_CODE = 'pollux'; | ||
const PLX_ENDPOINT_URL = '//adn.plxnt.com/prebid/v1'; | ||
const PLX_CURRENCY = 'EUR'; | ||
const PLX_TTL = 3600; | ||
const PLX_NETREVENUE = true; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['plx'], | ||
/** | ||
* 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.hasOwnProperty('params') || !bid.params.hasOwnProperty('zone')) { | ||
utils.logError('required param "zone" is missing'); | ||
return false; | ||
} | ||
return true; | ||
}, | ||
/** | ||
* 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) { | ||
if (!Array.isArray(validBidRequests) || !validBidRequests.length) { | ||
return []; | ||
} | ||
const payload = []; | ||
var custom_url = null; | ||
for (var i = 0; i < validBidRequests.length; i++) { | ||
const bid = validBidRequests[i]; | ||
const request = { | ||
bidId: bid.bidId, | ||
zones: bid.params.zone, | ||
sizes: bid.sizes | ||
}; | ||
if (bid.bidderUrl && !custom_url) { | ||
custom_url = bid.bidderUrl; | ||
} | ||
var prebidUrl = bidderUrl + '?' + utils.parseQueryStringParameters(request_obj); | ||
utils.logMessage('Pollux request built: ' + prebidUrl); | ||
adloader.loadScript(prebidUrl, null, true); | ||
payload.push(request); | ||
} | ||
} | ||
|
||
// expose the callback to global object | ||
function _polluxHandler (response) { | ||
// pollux handler | ||
var bidObject = {}; | ||
var callback_id = response.callback_id; | ||
var placementCode = ''; | ||
var bidObj = utils.getBidRequest(callback_id); | ||
if (bidObj) { | ||
placementCode = bidObj.placementCode; | ||
const payloadString = JSON.stringify(payload); | ||
// build url parameters | ||
const domain = utils.getParameterByName('domain'); | ||
const tracker2 = utils.getParameterByName('tracker2'); | ||
const url_params = {}; | ||
if (domain) { | ||
url_params.domain = domain; | ||
} else { | ||
url_params.domain = utils.getTopWindowUrl(); | ||
} | ||
if (tracker2) { | ||
url_params.tracker2 = tracker2; | ||
} | ||
// build url | ||
var bidder_url = custom_url || PLX_ENDPOINT_URL; | ||
if (url_params) { | ||
bidder_url = bidder_url + '?' + utils.parseQueryStringParameters(url_params); | ||
} | ||
utils.logMessage('Pollux request built: ' + bidder_url); | ||
return { | ||
method: 'POST', | ||
url: bidder_url, | ||
data: payloadString | ||
}; | ||
}, | ||
/** | ||
* 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 (!Array.isArray(serverResponse) || !serverResponse.length) { | ||
utils.logMessage('No prebid response from polluxHandler for bid requests:'); | ||
utils.logMessage(bidRequest); | ||
return []; | ||
} | ||
if (bidObj && response.cpm > 0 && !!response.ad) { | ||
bidObject = bidfactory.createBid(STATUS.GOOD, bidObj); | ||
bidObject.bidderCode = bidObj.bidder; | ||
bidObject.mediaType = response.mediaType; | ||
bidObject.cpm = parseFloat(response.cpm); | ||
if (response.ad_type === 'url') { | ||
bidObject.adUrl = response.ad; | ||
// loop through serverResponses | ||
const bidResponses = []; | ||
for (var b in serverResponse) { | ||
var bid = serverResponse[b]; | ||
const bidResponse = { | ||
requestId: bid.bidId, // not request id, it's bid's id | ||
bidderCode: spec.code, | ||
cpm: parseFloat(bid.cpm), | ||
width: parseInt(bid.width), | ||
height: parseInt(bid.height), | ||
ttl: PLX_TTL, | ||
creativeId: bid.creativeId, | ||
netRevenue: PLX_NETREVENUE, | ||
currency: PLX_CURRENCY | ||
}; | ||
if (bid.ad_type === 'url') { | ||
bidResponse.adUrl = bid.ad; | ||
} else { | ||
bidObject.ad = response.ad; | ||
bidResponse.ad = bid.ad; | ||
} | ||
bidObject.width = response.width; | ||
bidObject.height = response.height; | ||
} else { | ||
bidObject = bidfactory.createBid(STATUS.NO_BID, bidObj); | ||
bidObject.bidderCode = 'pollux'; | ||
utils.logMessage('No prebid response from polluxHandler for placement code ' + placementCode); | ||
if (bid.referrer) { | ||
bidResponse.referrer = bid.referrer; | ||
} | ||
bidResponses.push(bidResponse); | ||
} | ||
bidmanager.addBidResponse(placementCode, bidObject); | ||
}; | ||
$$PREBID_GLOBAL$$.polluxHandler = _polluxHandler; | ||
// Export the `callBids` function, so that Prebid.js can execute | ||
// this function when the page asks to send out bid requests. | ||
return { | ||
callBids: _callBids, | ||
polluxHandler: _polluxHandler | ||
}; | ||
return bidResponses; | ||
} | ||
}; | ||
adaptermanager.registerBidAdapter(new PolluxBidAdapter(), 'pollux'); | ||
module.exports = PolluxBidAdapter; | ||
registerBidder(spec); |
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.
Please drop
bidderCode
here. It's not required and in fact breaks adapter aliasing. Thanks sorry for the confusion.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.
Will do, but just enlight me here :)
"bidderCode" was a required parameter before, or at least it was in the docs right?
Thanks for your help
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.
Right on both counts. We have since fixed the documentation to omit that param. Thanks