-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Prebid Server to Server #1165
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
fccc7b4
s2s
mkendall07 1bcd3cb
-update
mkendall07 653e040
Revert "-update"
mkendall07 a856346
fixed heigth and width
mkendall07 72f5b96
updates
mkendall07 d901841
Prebid server to server
jaiminpanchal27 82c4337
Add cookie sync
mkendall07 acde99f
Adding bid to bidsRequested
jaiminpanchal27 395b09c
Merge branch 'experiment/s2s' of github.com:prebid/Prebid.js into exp…
jaiminpanchal27 7db4c80
Updated bid_id code returned by server
jaiminpanchal27 4ce87a1
update per URL coming back in response
mkendall07 fe78d5b
Merge branch 'experiment/s2s' of https://github.com/prebid/Prebid.js …
mkendall07 c0db945
saving bid requests in adapter
jaiminpanchal27 b399c41
Merge branch 'experiment/s2s' of github.com:prebid/Prebid.js into exp…
jaiminpanchal27 f3faf41
Unit tests for s2s adapter
jaiminpanchal27 87fd4c2
Handling no bid response and cookie sync url updates
jaiminpanchal27 fc019b9
Code refactor, added new param to s2sConfig public api
jaiminpanchal27 dc436d7
Merge branch 'master' of github.com:prebid/Prebid.js into experiment/s2s
jaiminpanchal27 bfac3d1
Added missing functions back and updated endpoint
jaiminpanchal27 93adadb
Added required param check and unit tests
jaiminpanchal27 34d89ec
top url fix
jaiminpanchal27 b485afb
Remove clutter and bug fix
jaiminpanchal27 467a643
Add cookie persist.
mkendall07 952bb2c
Rename s2s to prebidServer.
mkendall07 55ab4c5
Add back unit tests.
mkendall07 9b00658
Update cookie persist.
mkendall07 b7eeae7
Merge branch 'master' of github.com:prebid/Prebid.js into experiment/s2s
jaiminpanchal27 5638bc2
substitute for the `${AUCTION_PRICE}` macro
mkendall07 bdf5eda
address review notes
mkendall07 42d5628
Merge branch 'master' into experiment/s2s
jaiminpanchal27 86de494
Adding adapter back
jaiminpanchal27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ | |
"atomx", | ||
"tapsense", | ||
"trion", | ||
"prebidServer", | ||
"adsupply", | ||
{ | ||
"appnexus": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>.`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should look at how to make this configurable by pubs. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,8 @@ | |
"hb_pb", | ||
"hb_size", | ||
"hb_deal" | ||
] | ||
], | ||
"S2S" : { | ||
"DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/auction" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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