Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prebid Server to Server #1165

Merged
merged 31 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fccc7b4
s2s
mkendall07 Mar 28, 2017
1bcd3cb
-update
mkendall07 Mar 30, 2017
653e040
Revert "-update"
mkendall07 Apr 6, 2017
a856346
fixed heigth and width
mkendall07 Apr 6, 2017
72f5b96
updates
mkendall07 Apr 10, 2017
d901841
Prebid server to server
jaiminpanchal27 Apr 14, 2017
82c4337
Add cookie sync
mkendall07 Apr 17, 2017
acde99f
Adding bid to bidsRequested
jaiminpanchal27 Apr 19, 2017
395b09c
Merge branch 'experiment/s2s' of github.com:prebid/Prebid.js into exp…
jaiminpanchal27 Apr 19, 2017
7db4c80
Updated bid_id code returned by server
jaiminpanchal27 Apr 20, 2017
4ce87a1
update per URL coming back in response
mkendall07 Apr 20, 2017
fe78d5b
Merge branch 'experiment/s2s' of https://github.com/prebid/Prebid.js …
mkendall07 Apr 20, 2017
c0db945
saving bid requests in adapter
jaiminpanchal27 Apr 20, 2017
b399c41
Merge branch 'experiment/s2s' of github.com:prebid/Prebid.js into exp…
jaiminpanchal27 Apr 20, 2017
f3faf41
Unit tests for s2s adapter
jaiminpanchal27 Apr 20, 2017
87fd4c2
Handling no bid response and cookie sync url updates
jaiminpanchal27 Apr 24, 2017
fc019b9
Code refactor, added new param to s2sConfig public api
jaiminpanchal27 Apr 25, 2017
dc436d7
Merge branch 'master' of github.com:prebid/Prebid.js into experiment/s2s
jaiminpanchal27 Apr 27, 2017
bfac3d1
Added missing functions back and updated endpoint
jaiminpanchal27 Apr 28, 2017
93adadb
Added required param check and unit tests
jaiminpanchal27 Apr 28, 2017
34d89ec
top url fix
jaiminpanchal27 Apr 28, 2017
b485afb
Remove clutter and bug fix
jaiminpanchal27 Apr 28, 2017
467a643
Add cookie persist.
mkendall07 Apr 30, 2017
952bb2c
Rename s2s to prebidServer.
mkendall07 Apr 30, 2017
55ab4c5
Add back unit tests.
mkendall07 Apr 30, 2017
9b00658
Update cookie persist.
mkendall07 Apr 30, 2017
b7eeae7
Merge branch 'master' of github.com:prebid/Prebid.js into experiment/s2s
jaiminpanchal27 May 1, 2017
5638bc2
substitute for the `${AUCTION_PRICE}` macro
mkendall07 May 2, 2017
bdf5eda
address review notes
mkendall07 May 2, 2017
42d5628
Merge branch 'master' into experiment/s2s
jaiminpanchal27 May 2, 2017
86de494
Adding adapter back
jaiminpanchal27 May 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"atomx",
"tapsense",
"trion",
"prebidServer",
"adsupply",
{
"appnexus": {
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>
68 changes: 67 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(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should make this more descriptive e.g. s2s_id?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually just that, a bid_id

bidderRequestId,
requestId
});
Expand All @@ -55,6 +57,51 @@ 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) => {
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 +127,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 +220,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
121 changes: 121 additions & 0 deletions src/adapters/prebidServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import Adapter from 'src/adapters/adapter';
import bidfactory from 'src/bidfactory';
import bidmanager from 'src/bidmanager';
import * as utils from 'src/utils';
import { ajax } from 'src/ajax';
import { STATUS } from 'src/constants';
import { queueSync, persist } from 'src/cookie.js';

const TYPE = 's2s';
const cookiePersistMessage = `Your browser may be blocking 3rd party cookies. By clicking on this page you allow Prebid Server and other advertising partners to place cookies to help us advertise. You can opt out of their cookies <a href="https://www.appnexus.com/en/company/platform-privacy-policy#choices" target="_blank">here</a>.`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should look at how to make this configurable by pubs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of using prebid server for now. So opt out would be don't use prebid server.

const cookiePersistUrl = '//ib.adnxs.com/seg?add=1&redir=';
/**
* Bidder adapter for Prebid Server
*/
function PrebidServer() {

let baseAdapter = Adapter.createNew('prebidServer');
let bidRequests = [];
let config;

baseAdapter.setConfig = function(s2sconfig) {
config = s2sconfig;
};

/* Prebid executes this function when the page asks to send out bid requests */
baseAdapter.callBids = function(bidRequest) {

bidRequest.ad_units.forEach(adUnit => {
adUnit.bids.forEach(bidder => {
bidRequests[bidder.bidder] = utils.getBidRequest(bidder.bid_id);
});
});

let requestJson = {
account_id : config.accountId,
tid : bidRequest.tid,
max_bids: config.maxBids,
timeout_millis : config.timeout,
url: utils.getTopWindowUrl(),
prebid_version : '$prebid.version$',
ad_units : bidRequest.ad_units
};

const payload = JSON.stringify(requestJson);
ajax(config.endpoint, handleResponse, payload, {
contentType: 'text/plain',
withCredentials : true
});
};

/* Notify Prebid of bid responses so bids can get in the auction */
function handleResponse(response) {
let result;
try {
result = JSON.parse(response);

if(result.status === 'OK') {
if(result.bidder_status) {
result.bidder_status.forEach(bidder => {
if(bidder.no_bid || bidder.no_cookie) {
let bidRequest = bidRequests[bidder.bidder];
let bidObject = bidfactory.createBid(STATUS.NO_BID, bidRequest);
bidObject.bidderCode = bidRequest.bidder;
bidmanager.addBidResponse(bidRequest.placementCode, bidObject);
}
if(bidder.no_cookie) {
queueSync({bidder: bidder.bidder, url : bidder.usersync.url, type : bidder.usersync.type});
}
});
}
if(result.bids) {
result.bids.forEach(bidObj => {
let bidRequest = utils.getBidRequest(bidObj.bid_id);
let cpm = bidObj.price;
let status;
if (cpm !== 0) {
status = STATUS.GOOD;
} else {
status = STATUS.NO_BID;
}

let bidObject = bidfactory.createBid(status, bidRequest);
bidObject.creative_id = bidObj.creative_id;
bidObject.bidderCode = bidObj.bidder;
bidObject.cpm = cpm;
bidObject.ad = bidObj.adm;
bidObject.width = bidObj.width;
bidObject.height = bidObj.height;

bidmanager.addBidResponse(bidObj.code, bidObject);
});
}
}
else if (result.status === 'no_cookie') {
//cookie sync
persist(cookiePersistUrl, cookiePersistMessage);
}
} catch (error) {
utils.logError(error);
}

if (!result || result.status && result.status.includes('Error')) {
utils.logError('error parsing response: ', result.status);
}
}

return {
setConfig : baseAdapter.setConfig,
createNew: PrebidServer.createNew,
callBids: baseAdapter.callBids,
setBidderCode: baseAdapter.setBidderCode,
type : TYPE
};

}

PrebidServer.createNew = function() {
return new PrebidServer();
};

module.exports = PrebidServer;
5 changes: 4 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
"hb_pb",
"hb_size",
"hb_deal"
]
],
"S2S" : {
"DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/auction"
}
}
Loading