-
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.
* Add Unruly Bid Adapter * Replace placementCode with adUnitCode
- Loading branch information
Showing
4 changed files
with
458 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<!-- Prebid Config Section START --> | ||
<!-- Make sure this is inserted before your GPT tag --> | ||
<script> | ||
var PREBID_TIMEOUT = 3000; | ||
|
||
var adUnits = [{ | ||
code: 'ad-slot', | ||
sizes: [[728, 90], [300, 250]], | ||
mediaTypes: { | ||
video: { | ||
context: 'outstream' | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'unruly', | ||
params: { | ||
targetingUUID: '6f15e139-5f18-49a1-b52f-87e5e69ee65e', | ||
siteId: 1081534 | ||
} | ||
} | ||
] | ||
}]; | ||
var pbjs = pbjs || {}; | ||
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); | ||
})(); | ||
|
||
</script> | ||
<!-- Prebid Config Section END --> | ||
|
||
<!-- Prebid Boilerplate Section START. No Need to Edit. --> | ||
<script> | ||
var googletag = googletag || {}; | ||
googletag.cmd = googletag.cmd || []; | ||
googletag.cmd.push(function() { | ||
googletag.pubads().disableInitialLoad(); | ||
}); | ||
|
||
|
||
pbjs.que.push(function() { | ||
pbjs.addAdUnits(adUnits); | ||
pbjs.requestBids({ | ||
bidsBackHandler: sendAdserverRequest | ||
}); | ||
pbjs.setConfig({ | ||
"currency": { | ||
"adServerCurrency": "USD", | ||
} | ||
}); | ||
}); | ||
|
||
function sendAdserverRequest() { | ||
if (pbjs.adserverRequestSent) | ||
return; | ||
pbjs.adserverRequestSent = true; | ||
googletag.cmd.push(function () { | ||
pbjs.que.push(function () { | ||
pbjs.setTargetingForGPTAsync(); | ||
googletag.pubads().refresh(); | ||
}); | ||
}); | ||
} | ||
; | ||
|
||
setTimeout(function () { | ||
sendAdserverRequest(); | ||
}, PREBID_TIMEOUT); | ||
|
||
</script> | ||
<!-- Prebid Boilerplate Section END --> | ||
|
||
<script> | ||
(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); | ||
})(); | ||
</script> | ||
|
||
<script> | ||
googletag.cmd.push(function () { | ||
googletag.defineSlot('/19968336/header-bid-tag1', [[728, 90], [300, 250]], 'ad-slot').addService(googletag.pubads()); | ||
googletag.pubads().enableSingleRequest(); | ||
googletag.enableServices(); | ||
}); | ||
</script> | ||
|
||
<style> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
</style> | ||
<title>test</title> | ||
</head> | ||
|
||
<body> | ||
<div id='ad-slot'> | ||
<script type='text/javascript'> | ||
googletag.cmd.push(function() { googletag.display('ad-slot'); }); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import * as utils from 'src/utils' | ||
import { Renderer } from 'src/Renderer' | ||
import { registerBidder } from 'src/adapters/bidderFactory' | ||
import { VIDEO } from 'src/mediaTypes' | ||
|
||
function configureUniversalTag (exchangeRenderer) { | ||
parent.window.unruly = parent.window.unruly || {}; | ||
parent.window.unruly['native'] = parent.window.unruly['native'] || {}; | ||
parent.window.unruly['native'].siteId = parent.window.unruly['native'].siteId || exchangeRenderer.siteId; | ||
parent.window.unruly['native'].supplyMode = 'prebid'; | ||
} | ||
|
||
function configureRendererQueue () { | ||
parent.window.unruly['native'].prebid = parent.window.unruly['native'].prebid || {}; | ||
parent.window.unruly['native'].prebid.uq = parent.window.unruly['native'].prebid.uq || []; | ||
} | ||
|
||
function notifyRenderer (bidResponseBid) { | ||
parent.window.unruly['native'].prebid.uq.push(['render', bidResponseBid]); | ||
} | ||
|
||
const serverResponseToBid = (bid, rendererInstance) => ({ | ||
requestId: bid.bidId, | ||
cpm: bid.cpm, | ||
width: bid.width, | ||
height: bid.height, | ||
vastUrl: bid.vastUrl, | ||
netRevenue: true, | ||
creativeId: bid.bidId, | ||
ttl: 360, | ||
currency: 'USD', | ||
renderer: rendererInstance | ||
}); | ||
|
||
const buildPrebidResponseAndInstallRenderer = bids => | ||
bids | ||
.filter(serverBid => !!utils.deepAccess(serverBid, 'ext.renderer')) | ||
.map(serverBid => { | ||
const exchangeRenderer = utils.deepAccess(serverBid, 'ext.renderer'); | ||
configureUniversalTag(exchangeRenderer); | ||
configureRendererQueue(); | ||
|
||
const rendererInstance = Renderer.install(Object.assign({}, exchangeRenderer, { callback: () => {} })); | ||
return { rendererInstance, serverBid }; | ||
}) | ||
.map( | ||
({rendererInstance, serverBid}) => { | ||
const prebidBid = serverResponseToBid(serverBid, rendererInstance); | ||
|
||
const rendererConfig = Object.assign( | ||
{}, | ||
prebidBid, | ||
{ | ||
renderer: rendererInstance, | ||
adUnitCode: serverBid.ext.adUnitCode | ||
} | ||
); | ||
|
||
rendererInstance.setRender(() => { notifyRenderer(rendererConfig) }); | ||
|
||
return prebidBid; | ||
} | ||
); | ||
|
||
export const adapter = { | ||
code: 'unruly', | ||
supportedMediaTypes: [ VIDEO ], | ||
isBidRequestValid: function(bid) { | ||
if (!bid) return false; | ||
|
||
const context = utils.deepAccess(bid, 'mediaTypes.video.context'); | ||
|
||
return bid.mediaType === 'video' || context === 'outstream'; | ||
}, | ||
|
||
buildRequests: function(validBidRequests) { | ||
const url = 'https://targeting.unrulymedia.com/prebid'; | ||
const method = 'POST'; | ||
const data = { bidRequests: validBidRequests }; | ||
const options = { contentType: 'application/json' }; | ||
|
||
return { | ||
url, | ||
method, | ||
data, | ||
options, | ||
}; | ||
}, | ||
|
||
interpretResponse: function(serverResponse = {}) { | ||
const serverResponseBody = serverResponse.body; | ||
const noBidsResponse = []; | ||
const isInvalidResponse = !serverResponseBody || !serverResponseBody.bids; | ||
|
||
return isInvalidResponse | ||
? noBidsResponse | ||
: buildPrebidResponseAndInstallRenderer(serverResponseBody.bids); | ||
} | ||
}; | ||
|
||
registerBidder(adapter); |
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,31 @@ | ||
# Overview | ||
|
||
**Module Name**: Unruly Bid Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: [email protected] | ||
|
||
# Description | ||
|
||
Module that connects to UnrulyX for bids. | ||
|
||
# Test Parameters | ||
|
||
```js | ||
const adUnits = [{ | ||
code: 'ad-slot', | ||
sizes: [[728, 90], [300, 250]], | ||
mediaTypes: { | ||
video: { | ||
context: 'outstream' | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'unruly', | ||
params: { | ||
targetingUUID: '6f15e139-5f18-49a1-b52f-87e5e69ee65e', | ||
siteId: 1081534 | ||
} | ||
} | ||
] | ||
}]; | ||
``` |
Oops, something went wrong.