forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from header-bidder/APPS-13502
feat(openx adapter): APPS-13502: Allow passing custom key values spec…
- Loading branch information
Showing
3 changed files
with
257 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,223 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
|
||
<script> | ||
|
||
|
||
var PREBID_TIMEOUT = 2500; | ||
|
||
var googletag = googletag || {}; | ||
googletag.cmd = googletag.cmd || []; | ||
// googletag.cmd.push(function () { | ||
// googletag.pubads().disableInitialLoad(); | ||
// }); | ||
|
||
/* pbjs.initAdserver will be called either when all bids are back, or | ||
when the timeout is reached. | ||
*/ | ||
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; | ||
} | ||
|
||
// Load GPT when timeout is reached. | ||
setTimeout(initAdserver, PREBID_TIMEOUT); | ||
|
||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
|
||
// Load the Prebid Javascript Library Async. We recommend loading it immediately after | ||
// the initAdserver() and setTimeout functions. | ||
(function () { | ||
var d = document; | ||
var pbs = d.createElement("script"); | ||
pbs.type = "text/javascript"; | ||
pbs.src = '/build/dev/prebid.js'; | ||
var target = d.getElementsByTagName("head")[0]; | ||
target.insertBefore(pbs, target.firstChild); | ||
})(); | ||
|
||
pbjs.que.push(function() { | ||
pbjs.addAdUnits([{ | ||
code: 'div1', | ||
sizes: [[728, 90]], | ||
bids: [ | ||
{ | ||
bidder: 'openx', | ||
params: { | ||
unit: '1611012595', | ||
delDomain: 'qa-v2-i35-presets.del-qa.openx.net', | ||
customParams: {'key1': 'val1', 'key2': 'val2'} | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'div2', | ||
sizes: [[300, 250]], | ||
bids: [ | ||
{ | ||
bidder: 'openx', | ||
params: { | ||
unit: '1611012595', | ||
delDomain: 'qa-v2-i35-presets.del-qa.openx.net' | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'div3', | ||
sizes: [[160, 600]], | ||
bids: [ | ||
{ | ||
bidder: 'openx', | ||
params: { | ||
unit: '1611012595', | ||
delDomain: 'qa-v2-i35-presets.del-qa.openx.net', | ||
customParams: {'key2': 'notval2'} | ||
} | ||
} | ||
] | ||
}]); | ||
|
||
pbjs.requestBids({ | ||
bidsBackHandler: function() { | ||
initAdserver(); | ||
} | ||
}); | ||
|
||
function _getBucketFromCPM(cpm, bm) { | ||
if (!bm) { | ||
bm = 1; | ||
} | ||
|
||
var price, | ||
pubRev = (cpm * 1000) / bm, | ||
pubRevOrMaxTier = Math.min(pubRev, 10 * 2000); | ||
|
||
// round round cpms < .025 up to .05 | ||
if (pubRevOrMaxTier > 0 && pubRevOrMaxTier < 25) { | ||
pubRevOrMaxTier = 25; | ||
} | ||
|
||
if (pubRev < 1000) {// 5 cents to 1 dollar | ||
price = Math.round(pubRevOrMaxTier / 50) * 5; | ||
} else if (pubRev < 5000) {// 10 cents up to 5 dollar | ||
price = Math.round(pubRevOrMaxTier / 100) * 10; | ||
} else {// 50 cent up to max | ||
price = Math.round(pubRevOrMaxTier / 500) * 50; | ||
} | ||
return price + ""; | ||
} | ||
|
||
|
||
pbjs.bidderSettings = { | ||
standard: { | ||
adserverTargeting: [ | ||
{ | ||
key: "hb_bidder", | ||
val: function (bidResponse) { | ||
return bidResponse.bidderCode; | ||
} | ||
}, { | ||
key: "hb_adid", | ||
val: function (bidResponse) { | ||
return bidResponse.adId; | ||
} | ||
}, { | ||
key: "hb_pb", | ||
val: function (bidResponse) { | ||
return bidResponse.pbMg; | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
|
||
|
||
}); | ||
|
||
</script> | ||
|
||
<script type='text/javascript'> | ||
var slots = {}; | ||
googletag.cmd.push(function() { | ||
googletag.pubads().addEventListener('slotRenderEnded', function(event) { | ||
console.log('Slot has been rendered:'); | ||
console.log(event); | ||
}); | ||
|
||
slots['slot1'] = googletag.defineSlot('/90577858/prebid_auid', [[728, 90]], 'div1').addService(googletag.pubads()); | ||
slots['slot2'] = googletag.defineSlot('/90577858/prebid_auid', [[300, 250]], 'div2').addService(googletag.pubads()); | ||
slots['slot3'] = googletag.defineSlot('/90577858/prebid_auid', [[160, 600]], 'div3').addService(googletag.pubads()); | ||
|
||
pbjs.que.push(function() { | ||
pbjs.setTargetingForGPTAsync(); | ||
}); | ||
|
||
googletag.pubads().enableSingleRequest(); | ||
googletag.enableServices(); | ||
}); | ||
|
||
function refresh(slots) { | ||
pbjs.requestBids({ | ||
bidsBackHandler: function() { | ||
|
||
googletag.cmd.push(function() { | ||
pbjs.que.push(function() { | ||
pbjs.setTargetingForGPTAsync(); | ||
}); | ||
googletag.pubads().refresh(slots); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
</script> | ||
</head> | ||
<body> | ||
|
||
<button onclick="refresh()">Slot 1 Refresh</button> | ||
|
||
<h3>Slot 1</h3> | ||
<div id='div1' style='width:728px; height:90px;'> | ||
<script type='text/javascript'> | ||
googletag.cmd.push(function() { | ||
googletag.display('div1'); | ||
}); | ||
</script> | ||
</div> | ||
|
||
<h3>Slot 2</h3> | ||
<div id='div2' style='width:300px; height:250px;'> | ||
<script type='text/javascript'> | ||
googletag.cmd.push(function() { | ||
googletag.display('div2'); | ||
}); | ||
</script> | ||
</div> | ||
|
||
<h3>Slot 3</h3> | ||
<div id='div3' style='width:160px; height:600px;'> | ||
<script type='text/javascript'> | ||
googletag.cmd.push(function() { | ||
googletag.display('div3'); | ||
}); | ||
</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