Skip to content

Commit b929a2f

Browse files
authored
Update some JS video examples to use local cache (#6523)
* fix videojs instream example * Fix jwplayer example 02 * update jwplayer 01
1 parent 24f8e44 commit b929a2f

8 files changed

Lines changed: 284 additions & 288 deletions

File tree

_includes/loadScript.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script type="text/javascript">
2+
function loadScript(url) {
3+
const scr = document.createElement('script');
4+
scr.src = url;
5+
return new Promise((resolve, reject) => {
6+
scr.onerror = reject;
7+
scr.onload = resolve;
8+
document.head.appendChild(scr);
9+
});
10+
}
11+
</script>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script>
2+
window.pbjs = window.pbjs || {};
3+
pbjs.que = pbjs.que || [];
4+
pbjs.que.push(() => {
5+
pbjs.setConfig({
6+
debugging: {
7+
enabled: true,
8+
intercept: [
9+
{
10+
when: {},
11+
then: {
12+
cpm: 1,
13+
mediaType: "video",
14+
vastXml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><VAST version=\"3.0\"><Ad><InLine><AdSystem>GDFP</AdSystem><AdTitle>Demo</AdTitle><Description><![CDATA[Demo]]></Description><Creatives><Creative><Linear ><Duration>00:00:11</Duration><VideoClicks><ClickThrough><![CDATA[https://adplayer.pro/]]></ClickThrough></VideoClicks><MediaFiles><MediaFile delivery=\"progressive\" width=\"640\" height=\"360\" type=\"video/mp4\" scalable=\"true\" maintainAspectRatio=\"true\"><![CDATA[https://static.adplayer.pro/video/demo_v2.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>"
15+
}
16+
},
17+
]
18+
}
19+
})
20+
})
21+
</script>

_includes/video/pb-is-jw01.html

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,66 @@
33
<head>
44
{% include head--common.html %}
55
{% include prebidjs-non-prod.html %}
6+
{% include loadScript.html %}
7+
{% include video/mock-video-bid.html %}
68

79
<!--pbjs and player code -->
10+
<script type="text/javascript" class="cmplazyload" data-cmp-purpose="c51">
11+
loadScript('https://cdn.jwplayer.com/libraries/dNV4UKpE.js')
12+
.then(() => {
13+
//Test Key - replace this with your own valid JWPlayer license key
14+
jwplayer.key = "ssbF6k0i9BPe87xfG/s0ipdp5gwbLoZaDON/GQvuwPU9nVJy";
815

9-
<script>
10-
var pbjs = pbjs || {};
11-
pbjs.que = pbjs.que || [];
16+
window.pbjs = window.pbjs || {};
17+
pbjs.que = pbjs.que || [];
1218

13-
// define invokeVideoPlayer in advance in case we get the bids back from prebid before the entire page loads
14-
var tempTag = false;
15-
var invokeVideoPlayer = function (url) {
16-
tempTag = url;
17-
};
18-
19-
var videoAdUnit = {
20-
code: "video1",
21-
mediaTypes: {
22-
video: {
23-
context: "instream",
24-
playerSize: [640, 480],
25-
mimes: ["video/mp4"],
26-
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
27-
playbackmethod: [2],
28-
skip: 1,
29-
},
30-
},
31-
bids: [
32-
{
33-
bidder: "appnexus",
34-
params: {
35-
placementId: 13232361, // Add your own placement id here
19+
var videoAdUnit = {
20+
code: "video1",
21+
mediaTypes: {
22+
video: {
23+
context: "instream",
24+
playerSize: [640, 480],
25+
mimes: ["video/mp4"],
26+
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
27+
playbackmethod: [2],
28+
skip: 1,
29+
},
3630
},
37-
},
38-
],
39-
};
40-
41-
pbjs.que.push(function () {
42-
pbjs.addAdUnits(videoAdUnit); // add your ad units to the bid request
31+
bids: [
32+
{
33+
bidder: "appnexus",
34+
params: {
35+
placementId: 13232361, // Add your own placement id here
36+
},
37+
},
38+
],
39+
};
4340

44-
pbjs.setConfig({
45-
debug: true,
46-
cache: {
47-
url: "https://prebid.example.com/pbc/v1/cache",
48-
},
49-
});
41+
pbjs.que.push(function () {
42+
pbjs.addAdUnits(videoAdUnit); // add your ad units to the bid request
43+
pbjs.setConfig({
44+
debug: true,
45+
cache: {
46+
useLocal: true
47+
},
48+
});
5049

51-
pbjs.requestBids({
52-
bidsBackHandler: function (bids) {
53-
var videoUrl = pbjs.adServers.dfp.buildVideoUrl({
54-
adUnit: videoAdUnit,
55-
params: {
56-
iu: "/19968336/prebid_cache_video_adunit",
57-
cust_params: {
58-
section: "blog",
59-
anotherKey: "anotherValue",
60-
},
61-
output: "vast",
50+
pbjs.requestBids({
51+
bidsBackHandler: function (bids) {
52+
pbjs.adServers.gam.getVastXml({
53+
bid: bids.video1.bids[0],
54+
adUnit: videoAdUnit,
55+
params: {
56+
iu: '/41758329/localcache',
57+
},
58+
}).then(vastXml => {
59+
window.runJWPlayer(vastXml);
60+
})
6261
},
6362
});
64-
window.runJWPlayer(videoUrl);
65-
},
66-
});
67-
});
63+
});
64+
65+
})
6866
</script>
6967
</head>
7068

_includes/video/pb-is-jw02.html

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,67 @@
22
<html lang="en" class="html--no-js">
33
<head>
44
{% include head--common.html %} {% include prebidjs-non-prod.html %}
5+
{% include loadScript.html %}
6+
{% include video/mock-video-bid.html %}
57

6-
<!--pbjs and player code -->
7-
<script type="text/plain" class="cmplazyload" data-cmp-purpose="c51">
8-
function updateJWPlayer() {
9-
jwplayer.key = "ssbF6k0i9BPe87xfG/s0ipdp5gwbLoZaDON/GQvuwPU9nVJy"; //Test Key - replace this with your own valid JWPlayer license key
10-
}
11-
</script>
128

13-
<script
14-
type="text/plain"
15-
class="cmplazyload"
16-
data-cmp-purpose="c51"
17-
data-cmp-src="https://ssl.p.jwpcdn.com/player/v/8.0.5/jwplayer.js"
18-
></script>
9+
<script type="text/javascript" class="cmplazyload" data-cmp-purpose="c51">
10+
loadScript('https://ssl.p.jwpcdn.com/player/v/8.0.5/jwplayer.js')
11+
.then(() => {
12+
//Test Key - replace this with your own valid JWPlayer license key
13+
jwplayer.key = "ssbF6k0i9BPe87xfG/s0ipdp5gwbLoZaDON/GQvuwPU9nVJy";
1914

20-
<script>
21-
var pbjs = pbjs || {};
22-
pbjs.que = pbjs.que || [];
15+
window.pbjs = window.pbjs || {};
16+
pbjs.que = pbjs.que || [];
2317

24-
var videoAdUnit = {
25-
code: "video1",
26-
mediaTypes: {
27-
video: {
28-
context: "instream",
29-
playerSize: [640, 480],
30-
mimes: ["video/mp4"],
31-
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
32-
playbackmethod: [2],
33-
skip: 1,
34-
},
35-
},
36-
bids: [
37-
{
38-
bidder: "appnexus",
39-
params: {
40-
placementId: 13232361, // Add your own placement id here
18+
var videoAdUnit = {
19+
code: "video1",
20+
mediaTypes: {
21+
video: {
22+
context: "instream",
23+
playerSize: [640, 480],
24+
mimes: ["video/mp4"],
25+
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
26+
playbackmethod: [2],
27+
skip: 1,
28+
},
4129
},
42-
},
43-
],
44-
};
30+
bids: [
31+
{
32+
bidder: "appnexus",
33+
params: {
34+
placementId: 13232361, // Add your own placement id here
35+
},
36+
},
37+
],
38+
};
4539

46-
pbjs.que.push(function () {
47-
pbjs.addAdUnits(videoAdUnit); // add your ad units to the bid request
48-
pbjs.setConfig({
49-
debug: true,
50-
cache: {
51-
url: "https://prebid.example.com/pbc/v1/cache",
52-
},
53-
});
40+
pbjs.que.push(function () {
41+
pbjs.addAdUnits(videoAdUnit); // add your ad units to the bid request
42+
pbjs.setConfig({
43+
debug: true,
44+
cache: {
45+
useLocal: true
46+
},
47+
});
48+
49+
pbjs.requestBids({
50+
bidsBackHandler: function (bids) {
51+
pbjs.adServers.gam.getVastXml({
52+
bid: bids.video1.bids[0],
53+
adUnit: videoAdUnit,
54+
params: {
55+
iu: '/41758329/localcache',
56+
},
57+
}).then(vastXml => {
58+
window.runJWPlayer(vastXml);
59+
})
5460

55-
pbjs.requestBids({
56-
bidsBackHandler: function (bids) {
57-
var videoUrl = pbjs.adServers.dfp.buildVideoUrl({
58-
adUnit: videoAdUnit,
59-
params: {
60-
iu: "/19968336/prebid_cache_video_adunit",
61-
cust_params: {
62-
section: "blog",
63-
anotherKey: "anotherValue",
64-
},
65-
output: "vast",
6661
},
6762
});
68-
window.runJWPlayer(videoUrl);
69-
},
70-
});
71-
});
63+
});
64+
65+
})
7266
</script>
7367
</head>
7468

0 commit comments

Comments
 (0)