Skip to content

Commit

Permalink
Changes to support Prebid 5.0 API Change
Browse files Browse the repository at this point in the history
Changes for:
Adapter does not seem capable of supporting advertiserDomains prebid#6650
Support video params at the adunit level prebid#6512
Bid adapters that support floors must support the floors module prebid#6465
  • Loading branch information
NeerajKrRai committed Jul 7, 2021
1 parent cd4d0d8 commit c8fa08a
Show file tree
Hide file tree
Showing 8 changed files with 847 additions and 24 deletions.
93 changes: 93 additions & 0 deletions integrationExamples/gpt/TestAvngAdapter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!--
This page calls a single bidder for a single ad slot. It can be considered a "hello world" example for using
Prebid with the Google Publisher Tag.
It also makes a good test page for new adapter PR submissions. Simply set your server's Bid Params object in the
bids array inside the adUnits, and it will use your adapter to load an ad.
NOTE that many ad servers won't send back an ad if the URL is localhost... so you might need to
set an alias in your /etc/hosts file so that you can load this page from a different domain.
-->

<html>
<head>
<script async src="../../build/dev/prebid.js"></script>
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<script>
var FAILSAFE_TIMEOUT = 3300;
var PREBID_TIMEOUT = 1000;

var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600], [320,50],[320,480]],
}
},
// Replace this object to test a new Adapter!
bids: [{
bidder: 'advangelists',
params: {
pubid: '36b1698d957fc35f63b95c35a7938fe2',
placement: 10931,
bidfloor: 0.01
}
}]

}];

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

</script>

<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,
timeout: PREBID_TIMEOUT
});
});

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();
}, FAILSAFE_TIMEOUT);

</script>

<script>
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());

googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>

<body>
<h2>Prebid.js Test</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>
115 changes: 115 additions & 0 deletions integrationExamples/gpt/pbjs_video_adUnit_Avng.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Prebid.js video adUnit example1</title>

<link href="http://vjs.zencdn.net/4.7.1/video-js.css" rel="stylesheet">
<link href="https://raw.githubusercontent.com/theonion/videojs-vast-plugin/master/lib/videojs-contrib-ads/videojs.ads.css" rel="stylesheet" type="text/css">
<link href="https://raw.githubusercontent.com/theonion/videojs-vast-plugin/master/videojs.vast.css" rel="stylesheet" type="text/css">

<style type="text/css">
.description {
background-color:#eee;
border: 1px solid #777;
padding: 10px;
font-size: .8em;
line-height: 1.5em;
font-family: Verdana, sans-serif;
}
.example-video-container {
display: inline-block;
}
</style>
<script src="/build/dev/prebid.js" async=true></script>
<script>

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

/*
adUnits can support video demand requests by setting 'mediaType' to
'video'. When an adUnit is configured to support video, all bidders
within that adUnit must be video-enabled as well, as configured in
adapters.json.
*/
var videoAdUnit = {
code: 'video1',
sizes: [320,480],
mediaTypes: {
video: {
playerSize : [[320, 480]],
context: 'instream',
skip: 1,
mimes : ['video/mp4', 'application/javascript'],
playbackmethod : [2,6],
maxduration: 30
}
},
bids: [
{
bidder: 'advangelists',
params: {
pubid: '36b1698d957fc35f63b95c35a7938fe2',
placement: 10931,

}
}
]
};

pbjs.que.push(function(){
pbjs.addAdUnits(videoAdUnit);
pbjs.requestBids({
timeout : 3000,
bidsBackHandler : function(bids) {
var adserverTag = '<dfp_tag>'; // base ad server tag, see: https://support.google.com/dfp_premium/answer/1068325
var options = {
'adserver': 'dfp',
'code': 'video1' //code that matches the video adUnit declared above
};
//generate URL
var masterTagUrl = pbjs.buildMasterVideoTagFromAdserverTag(adserverTag, options);
//send masterTagUrl to the video player
invokeVideoPlayer(masterTagUrl);

}
});
});


</script>
</head>
<body>

<div class="example-video-container">
<video id="vid1" class="video-js vjs-default-skin" autoplay controls preload="auto"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'
width='320'
height='480'
>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>

<p>Video Playback Not Supported</p>
</video>
</div>

<script>

var vid1 = videojs('vid1');
vid1.muted(true);
vid1.ads();

/*
This function called after prebid is back
*/
function invokeVideoPlayer(url) {
vid1.vast({
url: url
});
}
</script>

</body>
</html>
42 changes: 30 additions & 12 deletions modules/advangelistsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const BIDDER_CODE = 'advangelists';
export const VIDEO_ENDPOINT = 'https://nep.advangelists.com/xp/get?pubid=';// 0cf8d6d643e13d86a5b6374148a4afac';
export const BANNER_ENDPOINT = 'https://nep.advangelists.com/xp/get?pubid=';// 0cf8d6d643e13d86a5b6374148a4afac';
export const OUTSTREAM_SRC = 'https://player-cdn.beachfrontmedia.com/playerapi/loader/outstream.js';
export const VIDEO_TARGETING = ['mimes', 'playbackmethod', 'maxduration', 'skip'];
export const VIDEO_TARGETING = ['mimes', 'playbackmethod', 'maxduration', 'skip', 'playerSize', 'context'];
export const DEFAULT_MIMES = ['video/mp4', 'application/javascript'];

let pubid = '';
Expand Down Expand Up @@ -66,6 +66,7 @@ export const spec = {
height: response.seatbid[0].bid[0].h,
ttl: response.seatbid[0].bid[0].ttl || 60,
creativeId: response.seatbid[0].bid[0].crid,
meta: { 'advertiserDomains': response.seatbid[0].bid[0].adomain },
currency: response.cur,
mediaType: VIDEO,
netRevenue: true
Expand All @@ -92,6 +93,7 @@ export const spec = {
ttl: response.seatbid[0].bid[0].ttl || 60,
creativeId: response.seatbid[0].bid[0].crid,
currency: response.cur,
meta: { 'advertiserDomains': response.seatbid[0].bid[0].adomain },
mediaType: BANNER,
netRevenue: true
}
Expand All @@ -108,6 +110,16 @@ function isVideoBid(bid) {
return utils.deepAccess(bid, 'mediaTypes.video');
}

function getBannerBidFloor(bid) {
let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {};
return floorInfo.floor || getBannerBidParam(bid, 'bidfloor');
}

function getVideoBidFloor(bid) {
let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'video', size: '*' }) : {};
return floorInfo.floor || getVideoBidParam(bid, 'bidfloor');
}

function isVideoBidValid(bid) {
return isVideoBid(bid) && getVideoBidParam(bid, 'pubid') && getVideoBidParam(bid, 'placement');
}
Expand Down Expand Up @@ -198,12 +210,19 @@ function getTopWindowReferrer() {
}

function getVideoTargetingParams(bid) {
return Object.keys(Object(bid.params.video))
.filter(param => includes(VIDEO_TARGETING, param))
.reduce((obj, param) => {
obj[ param ] = bid.params.video[ param ];
return obj;
}, {});
const result = {};
const excludeProps = ['playerSize', 'context', 'w', 'h'];
Object.keys(Object(bid.mediaTypes.video))
.filter(key => !includes(excludeProps, key))
.forEach(key => {
result[ key ] = bid.mediaTypes.video[ key ];
});
Object.keys(Object(bid.params.video))
.filter(key => includes(VIDEO_TARGETING, key))
.forEach(key => {
result[ key ] = bid.params.video[ key ];
});
return result;
}

function createVideoRequestData(bid, bidderRequest) {
Expand All @@ -212,7 +231,7 @@ function createVideoRequestData(bid, bidderRequest) {

let sizes = getVideoSizes(bid);
let firstSize = getFirstSize(sizes);

let bidfloor = (getVideoBidFloor(bid) == null || typeof getVideoBidFloor(bid) == 'undefined') ? 2 : getVideoBidFloor(bid);
let video = getVideoTargetingParams(bid);
const o = {
'device': {
Expand All @@ -239,7 +258,6 @@ function createVideoRequestData(bid, bidderRequest) {
};

o.site['page'] = topLocation.href;
o.site['domain'] = topLocation.hostname;
o.site['search'] = topLocation.search;
o.site['domain'] = topLocation.hostname;
o.site['ref'] = topReferrer;
Expand Down Expand Up @@ -267,7 +285,7 @@ function createVideoRequestData(bid, bidderRequest) {
'displaymanager': '' + BIDDER_CODE,
'displaymanagerver': '' + ADAPTER_VERSION,
'tagId': placement,
'bidfloor': 2.0,
'bidfloor': bidfloor,
'bidfloorcur': 'USD',
'secure': secure,
'video': Object.assign({
Expand Down Expand Up @@ -300,6 +318,7 @@ function createBannerRequestData(bid, bidderRequest) {
let topReferrer = getTopWindowReferrer();

let sizes = getBannerSizes(bid);
let bidfloor = (getBannerBidFloor(bid) == null || typeof getBannerBidFloor(bid) == 'undefined') ? 2 : getBannerBidFloor(bid);

const o = {
'device': {
Expand Down Expand Up @@ -327,7 +346,6 @@ function createBannerRequestData(bid, bidderRequest) {
o.site['page'] = topLocation.href;
o.site['domain'] = topLocation.hostname;
o.site['search'] = topLocation.search;
o.site['domain'] = topLocation.hostname;
o.site['ref'] = topReferrer;
o.site['mobile'] = isMobile() ? 1 : 0;
const secure = topLocation.protocol.indexOf('https') === 0 ? 1 : 0;
Expand All @@ -354,7 +372,7 @@ function createBannerRequestData(bid, bidderRequest) {
'displaymanager': '' + BIDDER_CODE,
'displaymanagerver': '' + ADAPTER_VERSION,
'tagId': placement,
'bidfloor': 2.0,
'bidfloor': bidfloor,
'bidfloorcur': 'USD',
'secure': secure,
'banner': {
Expand Down
15 changes: 6 additions & 9 deletions modules/advangelistsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,19 @@ var videoAdUnit = {
mediaTypes: {
video: {
playerSize : [[320, 480]],
context: 'instream'
context: 'instream',
skip: 1,
mimes : ['video/mp4', 'application/javascript'],
playbackmethod : [2,6],
maxduration: 30
}
},
bids: [
{
bidder: 'advangelists',
params: {
pubid: '8537f00948fc37cc03c5f0f88e198a76',
placement: 1234,
video: {
id: 123,
skip: 1,
mimes : ['video/mp4', 'application/javascript'],
playbackmethod : [2,6],
maxduration: 30
}
placement: 1234
}
}
]
Expand Down
Loading

0 comments on commit c8fa08a

Please sign in to comment.