-
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.
Update Pollux Adapter to v1.0 (#1694)
* Added PolluxNetwork Bid Adapter Added module, test spec and integration example for Pollux Network Bid Adapter * Update Pollux domain Update Pollux default domain on prebid adapter * Export getParameterByName method On Utils.js make getParameterByName method public * Executed changes requested by @jaiminpanchal27 on 2017-08-01 Moved zone_728x90.html to integrationExamples/gpt/pollux_zone_728x90.html; Added bidRequest as second parameter to bidfactory.createBid() on Pollux Bid Adapter; Added more test cases to increase test coverage (at least 85%); Review Ref: - #1431 (review) * Fixed Eslint errors on commit f745fe1 * Executed changes requested on PR#1431 review #54993573 - Removed $$PREBID_GLOBAL$$ public vars in unit test; - Moved stubs creation and its restoration to beforeEach and afterEach hooks in unit test; - Exposed polluxHandler method on polluxBidAdapter. * Remove redundant export This line was added in #1409, removing this then I'll merge * Update Pollux Adapter to v1.0 * Changes requested on Pollux Adapter pull request #1694 review #74933409 * Changes requested on Pollux Adapter pull request #1694 review #75505070 Rmoved parameter bidderCode from bid responses * Fixed breaking changes to serverResponse in interpretResponse method Parameter serverResponse of method interpretResponse in bid adapter changed from array of bids to an object, where bids are now nested within its parameter body. Plus a refactor of var declaration and log messages. * Fix lint errors on push for commit cc653a
- Loading branch information
Showing
5 changed files
with
413 additions
and
282 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
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,120 @@ | ||
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 for == ' + BIDDER_CODE + ' =='); | ||
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 = []; | ||
let custom_url = null; | ||
for (let 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 | ||
let bidder_url = custom_url || PLX_ENDPOINT_URL; | ||
if (url_params) { | ||
bidder_url = bidder_url + '?' + utils.parseQueryStringParameters(url_params); | ||
} | ||
utils.logMessage('== ' + BIDDER_CODE + ' == 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) { | ||
let bidResponses = []; | ||
if (!serverResponse || (typeof serverResponse === 'object' && !serverResponse.hasOwnProperty('body'))) { | ||
utils.logMessage('No prebid response from == ' + BIDDER_CODE + ' == for bid requests:'); | ||
utils.logMessage(bidRequest); | ||
return bidResponses; | ||
} | ||
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; | ||
serverResponse = serverResponse.body; | ||
if (!Array.isArray(serverResponse) || !serverResponse.length) { | ||
utils.logMessage('No prebid response from == ' + BIDDER_CODE + ' == for bid requests:'); | ||
utils.logMessage(bidRequest); | ||
return bidResponses; | ||
} | ||
// loop through serverResponses | ||
for (let b in serverResponse) { | ||
let bid = serverResponse[b]; | ||
const bidResponse = { | ||
requestId: bid.bidId, // not request id, it's bid's id | ||
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.