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#97 in AOLP_ADS_JS/prebid.js from release/1.…
Browse files Browse the repository at this point in the history
…21.0 to aolgithub-master

* commit '4d573b42c5fbbabf23fed48fa042b75a72dd16b2': (31 commits)
  Added prebidServer in aolPartnersIds.json.
  Added adapters in aolPartnersIds.json.
  Added changelog entry.
  Prebid 0.23.1 Release
  Add trafficSourceCode + test (prebid#1184)
  Clear cookie sync to prevent multiple calls (prebid#1181)
  change s2s adapter to filter out units with empty sizes array (prebid#1179)
  Sharethrough: Change to using a closure for the callback from ajax to preserve bidObj (prebid#1108)
  check array length when mapping sizes (prebid#1180)
  Bugfix/encoding url (prebid#1178)
  add lodash as dependency (prebid#1174)
  fix size mapping for s2s (prebid#1175)
  Improve footer styling (prebid#1171)
  Bugfix: internal bids requested overwritten (prebid#1173)
  pre-release version bump
  Prebid 0.23.0 Release
  Yieldbot adapter - multiple requestBids per pageview (prebid#1146)
  Widespace adapter validate size fix (prebid#1140)
  Audience Network: bid when at least one valid slot size (prebid#1148)
  Quantcast adaptor (prebid#1063)
  ...
  • Loading branch information
vzhukovsky committed May 25, 2017
2 parents a7bfcc9 + 4d573b4 commit 51f0f73
Show file tree
Hide file tree
Showing 43 changed files with 2,445 additions and 279 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.js]
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
AOL Prebid 1.21.0
----------------
Updated to Prebid 0.23.1


AOL Prebid 1.20.0
----------------
Updated to Prebid 0.22.2
Expand Down
4 changes: 4 additions & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
"openx",
"piximedia",
"pubmatic",
"pubgears",
"pulsepoint",
"pulsepointLite",
"quantcast",
"rhythmone",
"rubicon",
"smartyads",
Expand Down Expand Up @@ -64,6 +66,8 @@
"atomx",
"tapsense",
"trion",
"prebidServer",
"adsupply",
{
"appnexus": {
"alias": "brealtime"
Expand Down
14 changes: 14 additions & 0 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@
zone: '2eb6bd58-865c-47ce-af7f-a918108c3fd2' // REQUIRED zone oid
}
},
{
bidder: 'quantcast',
params: {
publisherId: 'test-publisher', // REQUIRED Publisher Id provided by Quantcast
battr : [1,2] // OPTIONAL - Array of Blocked creative attributes as per OpenRTB Spec List 5.3
}
},
{
bidder: 'atomx',
params: {
Expand Down Expand Up @@ -363,6 +370,13 @@
pId: 123456 // REQUIRED Placement Id
}
},
{
bidder: 'quantcast',
params: {
publisherId: 'test-publisher', // REQUIRED Publisher Id provided by Quantcast
battr : [1,2] // OPTIONAL - Array of Blocked creative attributes as per OpenRTB Spec List 5.3
}
},
{
bidder: 'huddledmasses',
params: {
Expand Down
95 changes: 95 additions & 0 deletions integrationExamples/gpt/prebidServer_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<html>
<head>
<script>
var PREBID_TIMEOUT = 3000;

var googletag = googletag || {};
var sizes = [[728, 90],[300, 250], [300,600]];
googletag.cmd = googletag.cmd || [];

function initAdserver() {
if (pbjs.initAdserverSet) return;
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
pbjs.initAdserverSet = true;
};
setTimeout(initAdserver, PREBID_TIMEOUT);

var pbjs = pbjs || {};
pbjs.bidderTimeout = 3000;
pbjs.que = pbjs.que || [];
(function() {
var pbjsEl = document.createElement("script");
pbjsEl.type = "text/javascript";
pbjsEl.async = true;
pbjsEl.src = '/build/dev/prebid.js';
var pbjsTargetEl = document.getElementsByTagName("head")[0];
pbjsTargetEl.insertBefore(pbjsEl, pbjsTargetEl.firstChild);
})();

pbjs.que.push(function() {
var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
sizes: [[300, 250], [300,600]],
bids: [
{
bidder: 'appnexus',
params: {
placementId: '10433394'
}
}
]
}];

pbjs.setS2SConfig({
accountId : '1',
enabled : true, //default value set to false
bidders : ['appnexus'],
timeout : 1000, //default value is 1000
adapter : 'prebidServer', //if we have any other s2s adapter, default value is s2s
endpoint : 'https://prebid.adnxs.com/pbs/v1/auction?url_override=http%3A%2F%2Fwww.nytimes.com'
});

pbjs.addAdUnits(adUnits);

pbjs.requestBids({
bidsBackHandler: function(bidResponses) {
initAdserver();
}
})
});
</script>

<script>
googletag.cmd.push(function() {
var rightSlot = googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());

pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
});

googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>

<body>
<h2>Prebid.js S2S Example</h2>

<h5>Div-1</h5>
<div id='div-gpt-ad-1460505748561-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1460505748561-0'); });
</script>
</div>
</body>
</html>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prebid.js",
"version": "0.22.2",
"version": "0.23.1",
"description": "Header Bidding Management Library",
"main": "src/prebid.js",
"scripts": {
Expand Down Expand Up @@ -82,6 +82,7 @@
"karma-sinon-ie": "^2.0.0-rc10",
"karma-webpack": "^1.5.1",
"localtunnel": "^1.3.0",
"lodash": "^4.17.4",
"mkpath": "^1.0.0",
"mocha": "^1.21.4",
"mock-fs": "^3.11.0",
Expand Down
72 changes: 71 additions & 1 deletion src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { BaseAdapter } from './adapters/baseAdapter';
var _bidderRegistry = {};
exports.bidderRegistry = _bidderRegistry;

//create s2s settings objectType_function
let _s2sConfig = {};
var _analyticsRegistry = {};
let _bidderSequence = null;

Expand All @@ -31,7 +33,7 @@ function getBids({bidderCode, requestId, bidderRequestId, adUnits}) {
mediaType: adUnit.mediaType,
transactionId : adUnit.transactionId,
sizes: sizes,
bidId: utils.getUniqueIdentifierStr(),
bidId: bid.bid_id || utils.getUniqueIdentifierStr(),
bidderRequestId,
requestId
});
Expand All @@ -55,6 +57,55 @@ exports.callBids = ({adUnits, cbTimeout}) => {
bidderCodes = shuffle(bidderCodes);
}

if(_s2sConfig.enabled) {
//these are called on the s2s adapter
let adaptersServerSide = _s2sConfig.bidders;

//don't call these client side
bidderCodes = bidderCodes.filter((elm) => {
return !adaptersServerSide.includes(elm);
});
let adUnitsCopy = utils.cloneJson(adUnits);

//filter out client side bids
adUnitsCopy.forEach((adUnit) => {
if (adUnit.sizeMapping) {
adUnit.sizes = mapSizes(adUnit);
delete adUnit.sizeMapping;
}
adUnit.sizes = transformHeightWidth(adUnit);
adUnit.bids = adUnit.bids.filter((bid) => {
return adaptersServerSide.includes(bid.bidder);
}).map((bid) => {
bid.bid_id = utils.getUniqueIdentifierStr();
return bid;
});
});

let tid = utils.generateUUID();
adaptersServerSide.forEach(bidderCode => {
const bidderRequestId = utils.getUniqueIdentifierStr();
const bidderRequest = {
bidderCode,
requestId,
bidderRequestId,
tid,
bids: getBids({bidderCode, requestId, bidderRequestId, 'adUnits' : adUnitsCopy}),
start: new Date().getTime(),
auctionStart: auctionStart,
timeout: _s2sConfig.timeout
};
//Pushing server side bidder
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
});

let s2sBidRequest = {tid, 'ad_units' : adUnitsCopy};
let s2sAdapter = _bidderRegistry[_s2sConfig.adapter]; //jshint ignore:line
utils.logMessage(`CALLING S2S HEADER BIDDERS ==== ${adaptersServerSide.join(',')}`);
s2sAdapter.setConfig(_s2sConfig);
s2sAdapter.callBids(s2sBidRequest);
}

bidderCodes.forEach(bidderCode => {
const adapter = _bidderRegistry[bidderCode];
if (adapter) {
Expand All @@ -80,6 +131,21 @@ exports.callBids = ({adUnits, cbTimeout}) => {
});
};


function transformHeightWidth(adUnit) {
let sizesObj = [];
let sizes = utils.parseSizesInput(adUnit.sizes);
sizes.forEach(size => {
let heightWidth = size.split('x');
let sizeObj = {
'w' : parseInt(heightWidth[0]),
'h' : parseInt(heightWidth[1])
};
sizesObj.push(sizeObj);
});
return sizesObj;
}

exports.registerBidAdapter = function (bidAdaptor, bidderCode) {
if (bidAdaptor && bidderCode) {

Expand Down Expand Up @@ -158,6 +224,10 @@ exports.setBidderSequence = function (order) {
_bidderSequence = order;
};

exports.setS2SConfig = function (config) {
_s2sConfig = config;
};

/** INSERT ADAPTERS - DO NOT EDIT OR REMOVE */

/** END INSERT ADAPTERS */
Expand Down
86 changes: 86 additions & 0 deletions src/adapters/adsupply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');
var adloader = require('../adloader');
var utils = require('../utils');
const ADSUPPLY_CODE = 'adsupply';

var AdSupplyAdapter = function AdSupplyAdapter() {
function _validateParams(params) {
if (!params || !params.siteId || !params.zoneId || !params.endpointUrl || !params.clientId) {
return false;
}

if (typeof params.zoneId !== 'number' || params.zoneId <= 0) {
return false;
}

return true;
}

function _getRequestUrl(bid) {
var referrerUrl = encodeURIComponent(window.document.referrer);
var rand = encodeURIComponent(Math.floor(Math.random() * 100000 + 1));
var time = encodeURIComponent(new Date().getTimezoneOffset());
return '//' + bid.params.endpointUrl + '/banner.engine?id=' + bid.params.siteId + '&z=' + bid.params.zoneId + '&rand=' + rand + '&ver=async' + '&time=' + time + '&referrerurl=' + referrerUrl + '&abr=false' + '&hbt=1&cid=' + encodeURIComponent(bid.params.clientId);
}

$$PREBID_GLOBAL$$.adSupplyResponseHandler = function (bidId) {
if (!bidId) return;

var bidRequest = utils.getBidRequest(bidId);

if (!bidRequest || !bidRequest.params) return;

var clientId = bidRequest.params.clientId;
var zoneProp = 'b' + bidRequest.params.zoneId;

if (!window[clientId] || !window[clientId][zoneProp]) return;

var media = window[clientId][zoneProp].Media;

if (!media) return;

if (!media.Url || !media.Ecpm || typeof media.Ecpm !== 'number' || media.Ecpm <= 0) {
var noFillbject = bidfactory.createBid(2, bidRequest);
noFillbject.bidderCode = ADSUPPLY_CODE;
bidmanager.addBidResponse(bidRequest.placementCode, noFillbject);
} else {
var bidObject = bidfactory.createBid(1, bidRequest);
bidObject.bidderCode = ADSUPPLY_CODE;
bidObject.cpm = media.Ecpm;
bidObject.ad = '<iframe style="z-index: 5000001; margin: 0px; padding: 0px; border: none; width: ' + media.Width + 'px; height: ' + media.Height + 'px; " src="//' + bidRequest.params.endpointUrl + media.Url + '"></iframe>';
bidObject.width = media.Width;
bidObject.height = media.Height;
bidmanager.addBidResponse(bidRequest.placementCode, bidObject);
}
};

function _makeCallBackHandler(bidId) {
return function () {
$$PREBID_GLOBAL$$.adSupplyResponseHandler(bidId);
};
}

function _callBids(params) {
var bids = params.bids || [];
for (var i = 0; i < bids.length; i++) {
var bid = bids[i];
if (!_validateParams(bid.params)) continue;

var clientId = bid.params.clientId;
var zoneProp = 'b' + bid.params.zoneId;
window[clientId] = window[clientId] || {};
window.window[clientId][zoneProp] = window.window[clientId][zoneProp] || {};
window.window[clientId][zoneProp].Media = {};

var requestUrl = _getRequestUrl(bid);
adloader.loadScript(requestUrl, _makeCallBackHandler(bid.bidId));
}
}

return {
callBids: _callBids
};
};

module.exports = AdSupplyAdapter;
6 changes: 5 additions & 1 deletion src/adapters/analytics/aolPartnersIds.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@
"innity": 67,
"beachfront": 68,
"trion": 69,
"huddledmasses": 70
"huddledmasses": 70,
"pubgears": 71,
"adsupply": 72,
"quantcast": 73,
"prebidServer": 74
}
Loading

0 comments on commit 51f0f73

Please sign in to comment.