-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* s2s * -update * Revert "-update" This reverts commit 1bcd3cb. * fixed heigth and width * updates * Prebid server to server * Add cookie sync * Adding bid to bidsRequested * Updated bid_id code returned by server * update per URL coming back in response * saving bid requests in adapter * Unit tests for s2s adapter * Handling no bid response and cookie sync url updates * Code refactor, added new param to s2sConfig public api * Added missing functions back and updated endpoint * Added required param check and unit tests * top url fix * Remove clutter and bug fix * Add cookie persist. * Rename s2s to prebidServer. * Add back unit tests. * Update cookie persist. * substitute for the `${AUCTION_PRICE}` macro * address review notes * Adding adapter back
- Loading branch information
1 parent
c17c483
commit 4470c08
Showing
10 changed files
with
620 additions
and
9 deletions.
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 |
---|---|---|
|
@@ -65,6 +65,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>.`; | ||
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.