Skip to content

Commit

Permalink
Video Module: add demos for intercepting bids with bidsBackHandler (#…
Browse files Browse the repository at this point in the history
…10225)

* adds bids back handler ovrride demo

* adds JW Player demo
  • Loading branch information
karimMourra authored Jul 25, 2023
1 parent b12aa0e commit e53bed1
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
divId: 'player',
vendorCode: 1, // jwplayer vendorCode
playerConfig: {
licenseKey: 'IAjLREYRLylTWsfLN3FoN/O3iQLbs+AfgZLlkAoyH8gSf7TnNtmOLcR8CUY=',
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
params: {
vendorConfig: {
file: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
divId: 'player',
vendorCode: 1, // JW Player vendorCode
playerConfig: {
licenseKey: 'IAjLREYRLylTWsfLN3FoN/O3iQLbs+AfgZLlkAoyH8gSf7TnNtmOLcR8CUY=',
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
params: {
vendorConfig: {
file: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4',
Expand Down
137 changes: 137 additions & 0 deletions integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.jwplayer.com/libraries/l5MchIxB.js"></script>
<script async src="../../../build/dev/prebid.js"></script>

<title>JW Player with Bids Back Handler override</title>

<script>
// Setup ad units
const videoAdUnitCode = 'adUnitTestCode'
var videoAdUnit = {
code: videoAdUnitCode,
mediaTypes: {
video: {}
},
video: {
divId: 'player', // required to indicate which player is being used to render this ad unit.
},

bids: [{
bidder: 'ix',
params: {
siteId: '300',
}
}]
};

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

pbjs.que.push(function () {
pbjs.setConfig({
video: {
providers: [{
divId: 'player',
vendorCode: 1, // jwplayer vendorCode
playerConfig: {
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
params: {
vendorConfig: {
file: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4',
advertising: { client: 'vast' }
}
}
},
},]
},
debugging: {
enabled: true,
intercept: [
{
when: {
adUnitCode: videoAdUnitCode,
},
then: {
cpm: 25,
currency: 'USD',
netRevenue: 100,
creativeId: 'testCreativeId',
ttl: 500,
mediaType: "video",
vastUrl: "https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=",
ad: "<VAST version=\"3.0\"> <Ad id=\"123\"> <InLine> <AdSystem>PubMatic</AdSystem> <AdTitle>VAST 2.0 Instream Test</AdTitle> <Description>VAST 2.0 Instream Test</Description> <Error> <![CDATA[https://aktrack.pubmatic.com/er=[ERRORCODE]]]> </Error> <Impression> <![CDATA[https://aktrack.pubmatic.com?e=impression]]> </Impression> <Creatives> <Creative AdID=\"123\"> <Linear> <Duration>00:00:30</Duration> <TrackingEvents> <Tracking event=\"creativeView\"> <![CDATA[https://aktrack.pubmatic.com?e=creativeView]]> </Tracking> <Tracking event=\"start\"> <![CDATA[https://aktrack.pubmatic.com?e=start]]> </Tracking> <Tracking event=\"midpoint\"> <![CDATA[https://aktrack.pubmatic.com?e=midpoint]]> </Tracking> <Tracking event=\"firstQuartile\"> <![CDATA[https://aktrack.pubmatic.com?e=firstQuartile]]> </Tracking> <Tracking event=\"thirdQuartile\"> <![CDATA[https://aktrack.pubmatic.com?e=thirdQuartile]]> </Tracking> <Tracking event=\"complete\"> <![CDATA[https://aktrack.pubmatic.com?e=complete]]> </Tracking> </TrackingEvents> <VideoClicks> <ClickThrough> <![CDATA[https://www.pubmatic.com]]> </ClickThrough> </VideoClicks> <MediaFiles> <MediaFile delivery=\"progressive\" type=\"video/mp4\" bitrate=\"500\" width=\"480\" height=\"460\" scalable=\"true\" maintainAspectRatio=\"true\"> <![CDATA[https://staging.pubmatic.com:8443/test/spinning-logo-480x360_video.mp4]]> </MediaFile> <MediaFile delivery=\"progressive\" type=\"video/ogg\" bitrate=\"500\" width=\"480\" height=\"460\" scalable=\"true\" maintainAspectRatio=\"true\"> <![CDATA[https://staging.pubmatic.com:8443/test/spinning-logo-480x360_video.ogg]]> </MediaFile> <MediaFile delivery=\"progressive\" type=\"video/x-flv\" bitrate=\"500\" width=\"400\" height=\"300\" scalable=\"true\" maintainAspectRatio=\"true\"> <![CDATA[https://staging.pubmatic.com:8443/test/PubMatic_test_video.flv]]> </MediaFile> </MediaFiles> </Linear> </Creative> <Creative AdID=\"123\"> <NonLinearAds> <TrackingEvents></TrackingEvents> <NonLinear height=\"50\" width=\"300\" minSuggestedDuration=\"00:00:05\"> <StaticResource creativeType=\"image/jpeg\"> <![CDATA[https://staging.pubmatic.com:8443/test/PubMatic_LetsBeClear_300x50.jpeg]]> </StaticResource> <NonLinearClickThrough> <![CDATA[https://www.pubmatic.com]]> </NonLinearClickThrough> </NonLinear> </NonLinearAds> </Creative> <Creative AdID=\"123\"> <CompanionAds> <Companion width=\"300\" height=\"250\"> <StaticResource creativeType=\"image/jpeg\"> <![CDATA[https://staging.pubmatic.com:8443/test/PubMatic_LetsBeClear_320x250.jpg]]> </StaticResource> <CompanionClickThrough> <![CDATA[https://www.pubmatic.com]]> </CompanionClickThrough> </Companion> </CompanionAds> </Creative> </Creatives> </InLine> </Ad> </VAST>"
}
},
]
}
});

pbjs.addAdUnits([videoAdUnit]);

pbjs.onEvent('videoSetupComplete', e => {
console.log('player setup successfully: ', e);
});

pbjs.onEvent('videoSetupFailed', e => {
console.log('player setup failed: ', e);
});

pbjs.onEvent('videoAdError', e => {
console.log('Ad Error: ', e);
});

pbjs.onEvent('videoAdImpression', e => {
console.log('Ad Impression: ', e);
});

pbjs.onEvent('videoBidError', e => {
console.log('An Ad Error came from a Bid: ', e);
});

pbjs.onEvent('videoBidImpression', e => {
console.log('An Ad Impression came from a Bid: ', e);
});

pbjs.requestBids({
adUnitCodes: [videoAdUnitCode],
bidsBackHandler: function(bidResponses) {
const bidResponse = bidResponses[videoAdUnitCode];
if (!bidResponse) {
return;
}

bidResponse.bids.forEach(bid => {
const videoUrl = pbjs.adServers.dfp.buildVideoUrl({
adUnit: videoAdUnit,
url: bid.vastUrl,
params: {
iu: '/19968336/prebid_cache_video_adunit',
cust_params: {
section: "blog",
anotherKey: "anotherValue"
},
hl: "en",
output: "xml_vast2",
url: "https://www.example.com",
}
});

bid.vastUrl = videoUrl;
pbjs.videoModule.renderBid('player', bid);
});
}
});

});
</script>
</head>

<body>
<h2>JW Player with Bids Back Handler override</h2>
<h5>Div-1: Player placeholder div</h5>
<div id ="player"></div>
</body>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
divId: 'player',
vendorCode: 1, // vendorCode for jwplayer
playerConfig: {
licenseKey: 'IAjLREYRLylTWsfLN3FoN/O3iQLbs+AfgZLlkAoyH8gSf7TnNtmOLcR8CUY=',
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
params: {
vendorConfig: {
file: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4',
Expand Down
2 changes: 1 addition & 1 deletion integrationExamples/videoModule/jwplayer/eventsUI.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
divId: 'player',
vendorCode: 1, // jwplayer vendorCode
playerConfig: {
licenseKey: '577+5vXsluqV2Uy0drAS8wrgiqJlYijZxz3DmoYDm8FTJjdoIe8zYA==',
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
params: {
vendorConfig: {
playlist: [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
divId: 'player',
vendorCode: 1, // JW Player vendorCode
playerConfig: {
licenseKey: 'IAjLREYRLylTWsfLN3FoN/O3iQLbs+AfgZLlkAoyH8gSf7TnNtmOLcR8CUY=',
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
params: {
vendorConfig: {
file: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
divId: 'player',
vendorCode: 1, // JW Player vendorCode
playerConfig: {
licenseKey: 'IAjLREYRLylTWsfLN3FoN/O3iQLbs+AfgZLlkAoyH8gSf7TnNtmOLcR8CUY=',
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
params: {
vendorConfig: {
mediaid: 'XYXYXYXY',
Expand Down
2 changes: 1 addition & 1 deletion integrationExamples/videoModule/jwplayer/playlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
vendorCode: 1, // JW Player vendorCode
playerConfig: {
params: {
licenseKey: 'IAjLREYRLylTWsfLN3FoN/O3iQLbs+AfgZLlkAoyH8gSf7TnNtmOLcR8CUY=',
licenseKey: 'zwqnWJlovTKhXv2JIcKBj0Si//K7cVPmBDEyaILcAMw+nVKaizsJRA==',
vendorConfig: {
playlist: [{
mediaid: 'XYXYXYXY',
Expand Down
164 changes: 164 additions & 0 deletions integrationExamples/videoModule/videojs/bidsBackHandlerOverride.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://vjs.zencdn.net/7.20.2/video-js.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.9.0/videojs-contrib-ads.css"
integrity="sha512-0gIqgiX1dWTChdWUl8XGIBDFvLo7aTvmd6FAhJjzWx5bzYsCJTiPJLKqLF3q31IN4Kfrc0NbTO+EthoT6O0olQ=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-ima/1.11.0/videojs.ima.css"
integrity="sha512-vvsEsf+dZDp6wbommO1Jbb2bpFhVQjw6pIzfE5fUY5Fgkmsgn/16sQWegqrd236T69kK5F1SbGZ+yK46a9il5A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://vjs.zencdn.net/7.20.2/video.min.js"></script>
<script src="https://imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.9.0/videojs-contrib-ads.js"
integrity="sha512-XjyyAijQGlXZET35toG8igvVs8HvfVgKXGnbfAs2EpZ0o8vjJoIrxL9RBBQbQjzAODIe0jvWelFfZOA3Z/vdWg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-ima/1.11.0/videojs.ima.js"
integrity="sha512-9ocW9fl8CKJhZp4cmDpLDGPuTQ93gvw1iIS6daMYc5Y0Xh1all8iwdoI+iNmZpiydpdDGyKMTriXDX0wfs2OEg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script async src="../../../build/dev/prebid.js"></script>

<title>VideoJS with Bids Back Handler override</title>

<script>
// Setup ad units
const videoAdUnitCode = 'adUnitTestCode'
var videoAdUnit = {
code: videoAdUnitCode,
mediaTypes: {
video: {}
},
video: {
divId: 'player', // required to indicate which player is being used to render this ad unit.
},

bids: [{
bidder: 'ix',
params: {
siteId: '300',
}
}]
};

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

pbjs.que.push(function () {
pbjs.setConfig({
video: {
providers: [{
divId: 'player',
vendorCode: 2, // videojs vendorCode
playerConfig: {
params: {
adPluginConfig: {
numRedirects: 10
},
vendorConfig: {
controls: true,
autoplay: false,
preload: "auto",
}
}
}
},]
},
debugging: {
enabled: true,
intercept: [
{
when: {
adUnitCode: videoAdUnitCode,
},
then: {
cpm: 25,
currency: 'USD',
netRevenue: 100,
creativeId: 'testCreativeId',
ttl: 500,
mediaType: "video",
vastUrl: "https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=",
ad: "<VAST version=\"3.0\"> <Ad id=\"123\"> <InLine> <AdSystem>PubMatic</AdSystem> <AdTitle>VAST 2.0 Instream Test</AdTitle> <Description>VAST 2.0 Instream Test</Description> <Error> <![CDATA[https://aktrack.pubmatic.com/er=[ERRORCODE]]]> </Error> <Impression> <![CDATA[https://aktrack.pubmatic.com?e=impression]]> </Impression> <Creatives> <Creative AdID=\"123\"> <Linear> <Duration>00:00:30</Duration> <TrackingEvents> <Tracking event=\"creativeView\"> <![CDATA[https://aktrack.pubmatic.com?e=creativeView]]> </Tracking> <Tracking event=\"start\"> <![CDATA[https://aktrack.pubmatic.com?e=start]]> </Tracking> <Tracking event=\"midpoint\"> <![CDATA[https://aktrack.pubmatic.com?e=midpoint]]> </Tracking> <Tracking event=\"firstQuartile\"> <![CDATA[https://aktrack.pubmatic.com?e=firstQuartile]]> </Tracking> <Tracking event=\"thirdQuartile\"> <![CDATA[https://aktrack.pubmatic.com?e=thirdQuartile]]> </Tracking> <Tracking event=\"complete\"> <![CDATA[https://aktrack.pubmatic.com?e=complete]]> </Tracking> </TrackingEvents> <VideoClicks> <ClickThrough> <![CDATA[https://www.pubmatic.com]]> </ClickThrough> </VideoClicks> <MediaFiles> <MediaFile delivery=\"progressive\" type=\"video/mp4\" bitrate=\"500\" width=\"480\" height=\"460\" scalable=\"true\" maintainAspectRatio=\"true\"> <![CDATA[https://staging.pubmatic.com:8443/test/spinning-logo-480x360_video.mp4]]> </MediaFile> <MediaFile delivery=\"progressive\" type=\"video/ogg\" bitrate=\"500\" width=\"480\" height=\"460\" scalable=\"true\" maintainAspectRatio=\"true\"> <![CDATA[https://staging.pubmatic.com:8443/test/spinning-logo-480x360_video.ogg]]> </MediaFile> <MediaFile delivery=\"progressive\" type=\"video/x-flv\" bitrate=\"500\" width=\"400\" height=\"300\" scalable=\"true\" maintainAspectRatio=\"true\"> <![CDATA[https://staging.pubmatic.com:8443/test/PubMatic_test_video.flv]]> </MediaFile> </MediaFiles> </Linear> </Creative> <Creative AdID=\"123\"> <NonLinearAds> <TrackingEvents></TrackingEvents> <NonLinear height=\"50\" width=\"300\" minSuggestedDuration=\"00:00:05\"> <StaticResource creativeType=\"image/jpeg\"> <![CDATA[https://staging.pubmatic.com:8443/test/PubMatic_LetsBeClear_300x50.jpeg]]> </StaticResource> <NonLinearClickThrough> <![CDATA[https://www.pubmatic.com]]> </NonLinearClickThrough> </NonLinear> </NonLinearAds> </Creative> <Creative AdID=\"123\"> <CompanionAds> <Companion width=\"300\" height=\"250\"> <StaticResource creativeType=\"image/jpeg\"> <![CDATA[https://staging.pubmatic.com:8443/test/PubMatic_LetsBeClear_320x250.jpg]]> </StaticResource> <CompanionClickThrough> <![CDATA[https://www.pubmatic.com]]> </CompanionClickThrough> </Companion> </CompanionAds> </Creative> </Creatives> </InLine> </Ad> </VAST>"
}
},
]
}
});

pbjs.addAdUnits([videoAdUnit]);

pbjs.onEvent('videoSetupComplete', e => {
// Load media with its Metadata when the video player is done instantiating.
videojs('player').loadMedia({
id: 'XYXYXYXY',
src: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4',
title: 'Subaru Outback On Street And Dirt',
description: 'Smoking Tire takes the all-new Subaru Outback to the highest point we can find in hopes our customer-appreciation Balloon Launch will get some free T-shirts into the hands of our viewers.',
type: 'video/mp4'
});
});

pbjs.onEvent('videoSetupFailed', e => {
console.log('player setup failed: ', e);
});

pbjs.onEvent('videoAdError', e => {
console.log('Ad Error: ', e);
});

pbjs.onEvent('videoAdImpression', e => {
console.log('Ad Impression: ', e);
});

pbjs.onEvent('videoBidError', e => {
console.log('An Ad Error came from a Bid: ', e);
});

pbjs.onEvent('videoBidImpression', e => {
console.log('An Ad Impression came from a Bid: ', e);
});

pbjs.requestBids({
adUnitCodes: [videoAdUnitCode],
bidsBackHandler: function(bidResponses) {
const bidResponse = bidResponses[videoAdUnitCode];
if (!bidResponse) {
return;
}

bidResponse.bids.forEach(bid => {
const videoUrl = pbjs.adServers.dfp.buildVideoUrl({
adUnit: videoAdUnit,
url: bid.vastUrl,
params: {
iu: '/19968336/prebid_cache_video_adunit',
cust_params: {
section: "blog",
anotherKey: "anotherValue"
},
hl: "en",
output: "xml_vast2",
url: "https://www.example.com",
}
});

bid.vastUrl = videoUrl;
pbjs.videoModule.renderBid('player', bid);
});
}
});

});
</script>
</head>

<body>
<h2>VideoJS with Bids Back Handler override</h2>
<h5>Div-1: Player placeholder div</h5>
<video-js id='player' class="vjs-big-play-centered">
<source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4" type="video/mp4">
</video-js>
</body>

</html>
11 changes: 9 additions & 2 deletions modules/videojsVideoProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,15 @@ export function VideojsProvider(providerConfig, vjs_, adState_, timeState_, call
return;
}

player.ima.changeAdTag(adTagUrl);
player.ima.requestAds();
// The VideoJS IMA plugin version 1.11.0 will throw when the ad is empty.
try {
player.ima.changeAdTag(adTagUrl);
player.ima.requestAds();
} catch (e) {
/*
Handling is not required; ad errors are emitted automatically by video.js
*/
}
}

function onEvent(type, callback, payload) {
Expand Down

0 comments on commit e53bed1

Please sign in to comment.