Skip to content

Commit

Permalink
Merge tag '0.32.0' of https://github.com/prebid/Prebid.js into prebuilt
Browse files Browse the repository at this point in the history
* tag '0.32.0' of https://github.com/prebid/Prebid.js: (44 commits)
  Prebid 0.32.0 Release
  Commenting out tests that are failing in IE10 (prebid#1710)
  Update dfp.buildVideoUrl to accept adserver url (prebid#1663)
  Update rubicon adapter with new properties and 1.0 changes (prebid#1776)
  Added adUnitCode for compatibility (prebid#1781)
  Remove 'supported' from analytics adapter info (prebid#1780)
  Add TTL parameter to bid (prebid#1784)
  Update GetIntent adapter to 1.0 version (prebid#1721)
  Add `usePaymentRule` param to AN bidders (prebid#1778)
  New hooks API (replaces monkey-patching for currency) (prebid#1683)
  Change prebidServer to call client user syncs if they exist (prebid#1734)
  Fix Centro adapter to allow requests of the same units (prebid#1746)
  add vastUrl + media type for video bids Prebid Server (prebid#1739)
  Update adxcg adapter for prebid 1.0 (prebid#1741)
  Update yieldmoBid adapter request url (prebid#1771)
  Upgrade Quantcast adapter for Prebid 1.0 (prebid#1753)
  Fidelity Media Adapter update. Prebid v1.0 (prebid#1719)
  Kargo Adapter for Prebid 1.0 (prebid#1729)
  updated for prebid 1.0 api (prebid#1722)
  Add AdOcean adapter (prebid#1735)
  ...
  • Loading branch information
Mat Brown committed Nov 13, 2017
2 parents 5031367 + 9f4ffda commit d52f0c7
Show file tree
Hide file tree
Showing 87 changed files with 6,710 additions and 5,915 deletions.
15 changes: 2 additions & 13 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,7 @@

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2013 APPNEXUS INC
Copyright 2017 PREBID.ORG, INC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -199,4 +188,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ gulp.task('webpack', ['clean'], function () {
// By default, this runs in headless chrome.
//
// If --watch is given, the task will re-run unit tests whenever the source code changes
// If --file "<path-to-test-file>" is given, the task will only run tests in the specified file.
// If --browserstack is given, it will run the full suite of currently supported browsers.
// If --browsers is given, browsers can be chosen explicitly. e.g. --browsers=chrome,firefox,ie9
gulp.task('test', ['clean'], function (done) {
var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch);
var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch, argv.file);

var browserOverride = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase);
if (browserOverride.length > 0) {
Expand All @@ -185,8 +186,9 @@ gulp.task('test', ['clean'], function (done) {
new KarmaServer(karmaConf, newKarmaCallback(done)).start();
});

// If --file "<path-to-test-file>" is given, the task will only run tests in the specified file.
gulp.task('test-coverage', ['clean'], function(done) {
new KarmaServer(karmaConfMaker(true, false), newKarmaCallback(done)).start();
new KarmaServer(karmaConfMaker(true, false, false, argv.file), newKarmaCallback(done)).start();
});

// View the code coverage report in the browser.
Expand Down
4 changes: 2 additions & 2 deletions karma.conf.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ function setBrowsers(karmaConf, browserstack) {
}
}

module.exports = function(codeCoverage, browserstack, watchMode) {
module.exports = function(codeCoverage, browserstack, watchMode, file) {
var webpackConfig = newWebpackConfig(codeCoverage);
var plugins = newPluginsArray(browserstack);
var files = [
'test/helpers/prebidGlobal.js',
'test/**/*_spec.js'
file ? file : 'test/**/*_spec.js'
];
// This file opens the /debug.html tab automatically.
// It has no real value unless you're running --watch, and intend to do some debugging in the browser.
Expand Down
230 changes: 107 additions & 123 deletions modules/adbutlerBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,123 @@
/**
* @overview AdButler Prebid.js adapter.
* @author dkharton
*/

'use strict';

var utils = require('src/utils.js');
var adloader = require('src/adloader.js');
var bidmanager = require('src/bidmanager.js');
var bidfactory = require('src/bidfactory.js');
var adaptermanager = require('src/adaptermanager');

var AdButlerAdapter = function AdButlerAdapter() {
function _callBids(params) {
var bids = params.bids || [];
var callbackData = {};
var zoneCount = {};
var pageID = Math.floor(Math.random() * 10e6);

// Build and send bid requests
for (var i = 0; i < bids.length; i++) {
var bid = bids[i];
var zoneID = utils.getBidIdParameter('zoneID', bid.params);
var callbackID;

if (!(zoneID in zoneCount)) {
zoneCount[zoneID] = 0;
import * as utils from 'src/utils';
import {config} from 'src/config';
import {registerBidder} from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'adbutler';

export const spec = {
code: BIDDER_CODE,
pageID: Math.floor(Math.random() * 10e6),

isBidRequestValid: function (bid) {
return !!(bid.params.accountID && bid.params.zoneID);
},

buildRequests: function (validBidRequests) {
var i;
var zoneID;
var bidRequest;
var accountID;
var keyword;
var domain;
var requestURI;
var serverRequests = [];
var zoneCounters = {};

for (i = 0; i < validBidRequests.length; i++) {
bidRequest = validBidRequests[i];
zoneID = utils.getBidIdParameter('zoneID', bidRequest.params);
accountID = utils.getBidIdParameter('accountID', bidRequest.params);
keyword = utils.getBidIdParameter('keyword', bidRequest.params);
domain = utils.getBidIdParameter('domain', bidRequest.params);

if (!(zoneID in zoneCounters)) {
zoneCounters[zoneID] = 0;
}

// build callbackID to get placementCode later
callbackID = zoneID + '_' + zoneCount[zoneID];
if (typeof domain === 'undefined' || domain.length === 0) {
domain = 'servedbyadbutler.com';
}

callbackData[callbackID] = {};
callbackData[callbackID].bidId = bid.bidId;
requestURI = location.protocol + '//' + domain + '/adserve/;type=hbr;';
requestURI += 'ID=' + encodeURIComponent(accountID) + ';';
requestURI += 'setID=' + encodeURIComponent(zoneID) + ';';
requestURI += 'pid=' + encodeURIComponent(spec.pageID) + ';';
requestURI += 'place=' + encodeURIComponent(zoneCounters[zoneID]) + ';';

var adRequest = buildRequest(bid, zoneCount[zoneID], pageID);
zoneCount[zoneID]++;
// append the keyword for targeting if one was passed in
if (keyword !== '') {
requestURI += 'kw=' + encodeURIComponent(keyword) + ';';
}

adloader.loadScript(adRequest);
zoneCounters[zoneID]++;
serverRequests.push({
method: 'GET',
url: requestURI,
data: {},
bidRequest: bidRequest
});
}
return serverRequests;
},

interpretResponse: function (serverResponse, bidRequest) {
var bidObj = bidRequest.bidRequest;
var bidResponses = [];
var bidResponse = {};
var isCorrectSize = false;
var isCorrectCPM = true;
var CPM;
var minCPM;
var maxCPM;
var width;
var height;

serverResponse = serverResponse.body;
if (serverResponse && serverResponse.status === 'SUCCESS' && bidObj) {
CPM = serverResponse.cpm;
minCPM = utils.getBidIdParameter('minCPM', bidObj.params);
maxCPM = utils.getBidIdParameter('maxCPM', bidObj.params);
width = parseInt(serverResponse.width);
height = parseInt(serverResponse.height);

// Ensure response CPM is within the given bounds
if (minCPM !== '' && CPM < parseFloat(minCPM)) {
isCorrectCPM = false;
}
if (maxCPM !== '' && CPM > parseFloat(maxCPM)) {
isCorrectCPM = false;
}

// Define callback function for bid responses
$$PREBID_GLOBAL$$.adbutlerCB = function(aBResponseObject) {
var bidResponse = {};
var callbackID = aBResponseObject.zone_id + '_' + aBResponseObject.place;
var width = parseInt(aBResponseObject.width);
var height = parseInt(aBResponseObject.height);
var isCorrectSize = false;
var isCorrectCPM = true;
var CPM;
var minCPM;
var maxCPM;
var bidObj = callbackData[callbackID] ? utils.getBidRequest(callbackData[callbackID].bidId) : null;

if (bidObj) {
if (aBResponseObject.status === 'SUCCESS') {
CPM = aBResponseObject.cpm;
minCPM = utils.getBidIdParameter('minCPM', bidObj.params);
maxCPM = utils.getBidIdParameter('maxCPM', bidObj.params);

// Ensure response CPM is within the given bounds
if (minCPM !== '' && CPM < parseFloat(minCPM)) {
isCorrectCPM = false;
}
if (maxCPM !== '' && CPM > parseFloat(maxCPM)) {
isCorrectCPM = false;
}

// Ensure that response ad matches one of the placement sizes.
utils._each(bidObj.sizes, function(size) {
if (width === size[0] && height === size[1]) {
isCorrectSize = true;
}
});

if (isCorrectCPM && isCorrectSize) {
bidResponse = bidfactory.createBid(1, bidObj);
bidResponse.bidderCode = 'adbutler';
bidResponse.cpm = CPM;
bidResponse.width = width;
bidResponse.height = height;
bidResponse.ad = aBResponseObject.ad_code;
bidResponse.ad += addTrackingPixels(aBResponseObject.tracking_pixels);
} else {
bidResponse = bidfactory.createBid(2, bidObj);
bidResponse.bidderCode = 'adbutler';
}
} else {
bidResponse = bidfactory.createBid(2, bidObj);
bidResponse.bidderCode = 'adbutler';
// Ensure that response ad matches one of the placement sizes.
utils._each(bidObj.sizes, function (size) {
if (width === size[0] && height === size[1]) {
isCorrectSize = true;
}

bidmanager.addBidResponse(bidObj.placementCode, bidResponse);
});
if (isCorrectCPM && isCorrectSize) {
bidResponse.requestId = bidObj.bidId;
bidResponse.bidderCode = spec.code;
bidResponse.creativeId = serverResponse.placement_id;
bidResponse.cpm = CPM;
bidResponse.width = width;
bidResponse.height = height;
bidResponse.ad = serverResponse.ad_code;
bidResponse.ad += spec.addTrackingPixels(serverResponse.tracking_pixels);
bidResponse.currency = 'USD';
bidResponse.netRevenue = true;
bidResponse.ttl = config.getConfig('_bidderTimeout');
bidResponse.referrer = utils.getTopWindowUrl();
bidResponses.push(bidResponse);
}
};
}

function buildRequest(bid, adIndex, pageID) {
var accountID = utils.getBidIdParameter('accountID', bid.params);
var zoneID = utils.getBidIdParameter('zoneID', bid.params);
var keyword = utils.getBidIdParameter('keyword', bid.params);
var domain = utils.getBidIdParameter('domain', bid.params);

if (typeof domain === 'undefined' || domain.length === 0) {
domain = 'servedbyadbutler.com';
}
return bidResponses;
},

var requestURI = location.protocol + '//' + domain + '/adserve/;type=hbr;';
requestURI += 'ID=' + encodeURIComponent(accountID) + ';';
requestURI += 'setID=' + encodeURIComponent(zoneID) + ';';
requestURI += 'pid=' + encodeURIComponent(pageID) + ';';
requestURI += 'place=' + encodeURIComponent(adIndex) + ';';

// append the keyword for targeting if one was passed in
if (keyword !== '') {
requestURI += 'kw=' + encodeURIComponent(keyword) + ';';
}
requestURI += 'jsonpfunc=$$PREBID_GLOBAL$$.adbutlerCB;';
requestURI += 'click=CLICK_MACRO_PLACEHOLDER';

return requestURI;
}

function addTrackingPixels(trackingPixels) {
addTrackingPixels: function (trackingPixels) {
var trackingPixelMarkup = '';
utils._each(trackingPixels, function(pixelURL) {
utils._each(trackingPixels, function (pixelURL) {
var trackingPixel = '<img height="0" width="0" border="0" style="display:none;" src="';
trackingPixel += pixelURL;
trackingPixel += '">';
Expand All @@ -133,14 +126,5 @@ var AdButlerAdapter = function AdButlerAdapter() {
});
return trackingPixelMarkup;
}

// Export the callBids function, so that prebid.js can execute this function
// when the page asks to send out bid requests.
return {
callBids: _callBids
};
};

adaptermanager.registerBidAdapter(new AdButlerAdapter(), 'adbutler');

module.exports = AdButlerAdapter;
registerBidder(spec);
31 changes: 31 additions & 0 deletions modules/adbutlerBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Overview

**Module Name**: AdButler Bidder Adapter
**Module Type**: Bidder Adapter
**Maintainer**: dan@sparklit.com

# Description

Module that connects to an AdButler zone to fetch bids.

# Test Parameters
```
var adUnits = [
{
code: 'display-div',
sizes: [[300, 250]], // a display size
bids: [
{
bidder: "adbutler",
params: {
accountID: '167283',
zoneID: '210093',
keyword: 'red', //optional
minCPM: '1.00', //optional
maxCPM: '5.00' //optional
}
}
]
}
];
```
Loading

0 comments on commit d52f0c7

Please sign in to comment.