Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request prebid#131 in AOLP_ADS_JS/prebid.js from release/1…
Browse files Browse the repository at this point in the history
….32.0 to aolgithub-master

* commit '7a956351d69ed3a54ec31aaef17a36441be16fbd': (58 commits)
  Fixed wrong contentType and customHeader options.
  Fixed aol adapter bad merge (accepted official changes)
  Fixed issue with invalid webpack module.
  Added partners ids.
  Added changelog entry.
  Refactored interpretResponse tests for Prebid 1.0.
  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)
  Refactored get userSyncs tests for Prebid 1.0.
  Fixed faining tests for One Mobile endpoint.
  Refactored One Mobile tests for Prebid 1.0
  Refactored Marketplace tests for Prebid 1.0
  Implemented AOL user syncs config via setConfig API.
  Move one mobile post properties to options object.
  Update GetIntent adapter to 1.0 version (prebid#1721)
  ...
  • Loading branch information
vzhukovsky committed Dec 21, 2017
2 parents 0270758 + 7a95635 commit ab5a7db
Show file tree
Hide file tree
Showing 93 changed files with 7,130 additions and 6,508 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
AOL Prebid 1.32.0
----------------
Updated to Prebid 0.32.0


AOL Prebid 1.31.0
----------------
Updated to Prebid 0.31.0
Expand Down
13 changes: 1 addition & 12 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 2016 AOL INC.
Copyright 2017 AOL INC.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
Expand Down
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ gulp.task('build-aol-bundle', ['build-bundle-dev'], () => {
// 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 @@ -201,8 +202,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 @@ -97,12 +97,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 ab5a7db

Please sign in to comment.