Skip to content

Commit

Permalink
Update Pollux Adapter to v1.0 (#1694)
Browse files Browse the repository at this point in the history
* 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
hdjvieira authored and Matt Kendall committed Nov 10, 2017
1 parent ccbdf4a commit cb2cd77
Show file tree
Hide file tree
Showing 5 changed files with 413 additions and 282 deletions.
12 changes: 12 additions & 0 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@
placement_id: 0
}
},
{
bidder: 'pollux',
params: {
zone: '1806' // REQUIRED Zone Id (1806 is a test zone)
}
},
{
bidder: 'adkernelAdn',
params: {
Expand Down Expand Up @@ -395,6 +401,12 @@
params: {
placement_id: 0
}
},
{
bidder: 'pollux',
params: {
zone: '276' // REQUIRED Zone Id (276 is a test zone)
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,77 @@
var PREBID_TIMEOUT = 3000;

var adUnits = [{
code: 'div-gpt-ad-1460505661639-0',
sizes: [[728, 90]],
bids: [
{
bidder: 'pollux',
params: {
zone: '276'
}
},
{
bidder: 'pollux',
params: {
zone: '1806'
}
}
]
}];

code: 'div-gpt-ad-1460505661639-0',
sizes: [[728, 90], [300, 250]],
bids: [{
bidder: 'pollux',
params: {
zone: '1806,276'
}
}, {
bidder: 'pollux',
params: {
zone: '276'
}
}
]
},
{
code: 'div-gpt-ad-1460505661631-0',
sizes: [[300, 250]],
bids: [{
bidder: 'pollux',
params: {
zone: '1806,276,855'
}
}
]
}
];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
</script>
<!-- Prebid Config Section END -->

<!-- Prebid Boilerplate Section START. No Need to Edit. -->
<script type="text/javascript" src="//cdn-assetsx.plxnt.com/assets/public/js/prebid.js" async></script>
<script type="text/javascript" src="//cdn-assetsx.plxnt.com/assets/public/js/prebid/v1/prebid.js" async></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});


pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});
bidsBackHandler: sendAdserverRequest
});
pbjs.setConfig({
"currency": {
"adServerCurrency": "USD",
"granularityMultiplier": 1
}
});
});

function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
};
function sendAdserverRequest() {
if (pbjs.adserverRequestSent)
return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}
;

setTimeout(function() {
sendAdserverRequest();
}, PREBID_TIMEOUT);
setTimeout(function () {
sendAdserverRequest();
}, PREBID_TIMEOUT);

</script>
<!-- Prebid Boilerplate Section END -->
Expand All @@ -79,7 +97,8 @@

<script>
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag1', [[728, 90]], 'div-gpt-ad-1460505661639-0').addService(googletag.pubads());
googletag.defineSlot('/19968336/header-bid-tag1', [[728, 90], [300, 250]], 'div-gpt-ad-1460505661639-0').addService(googletag.pubads());
googletag.defineSlot('/19968336/header-bid-tag1', [[300, 250]], 'div-gpt-ad-1460505661631-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
Expand All @@ -100,5 +119,14 @@
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1460505661639-0'); });
</script>
</div>

<br>
<br>

<div id='div-gpt-ad-1460505661631-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1460505661631-0'); });
</script>
</div>
</body>
</html>
199 changes: 111 additions & 88 deletions modules/polluxBidAdapter.js
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);
Loading

0 comments on commit cb2cd77

Please sign in to comment.