Skip to content

Commit de62968

Browse files
authored
Update GAM video tutorial to explain local cache (#6527)
* local cache tutorial * lint
1 parent 4d90dde commit de62968

2 files changed

Lines changed: 72 additions & 14 deletions

File tree

dev-docs/modules/dfp_video.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ layout: page_v2
33
page_type: module
44
title: Module - Google Ad Manager Video
55
description: Required for serving instream video through Google Ad Manager.
6-
module_code : dfpAdServerVideo
6+
module_code : gamAdServerVideo
77
display_name : Google Ad Manager Video Support
88
enable_download : true
99
vendor_specific: true
1010
sidebarType : 1
1111
---
1212

1313

14-
1514
# Google Ad Manager Video
1615

1716
{:.no_toc}
@@ -27,7 +26,10 @@ The standard options:
2726

2827
## Step 2: Integrate into your prebid.js configuration
2928

30-
The method exposes the [`pbjs.adServers.dfp.buildVideoUrl`]({{site.baseurl}}/dev-docs/publisher-api-reference/adServers.dfp.buildVideoUrl.html) method to use. For an example, see the DFP video guide linked below.
29+
This module exposes the following methods:
30+
31+
- [`pbjs.adServers.gam.buildVideoUrl`](/dev-docs/publisher-api-reference/adServers.dfp.buildVideoUrl.html)
32+
- [`pbjs.adServers.gam.getVastXml`](/dev-docs/publisher-api-reference/adServers.dfp.getVastXml.html)
3133

3234
# Further Reading
3335

dev-docs/show-video-with-a-dfp-video-tag.md

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ The code example below was built using the following libraries:
2929
Also, you need to make sure to build Prebid.js with:
3030

3131
* Support for at least one video-enabled bidder
32-
* Support for the `dfpAdServerVideo` ad server adapter, which will provide the video ad support
32+
* Support for the `gamAdServerVideo` ad server adapter, which will provide the video ad support
3333

3434
For example, to build with the AppNexus bidder adapter and the Google Ad Manager
3535
Video ad server adapter, use the following command:
3636

3737
```bash
38-
gulp build --modules=dfpAdServerVideo,appnexusBidAdapter
38+
gulp build --modules=gamAdServerVideo,appnexusBidAdapter
3939
```
4040

4141
For more information about how to build with modules, see the [Prebid.js project README](https://github.com/prebid/Prebid.js/blob/master/README.md#build-optimization).
@@ -82,16 +82,15 @@ For full details on video ad unit parameters, see [Ad Unit Reference for Video](
8282

8383
By default, Prebid.js caps all CPMs at $20. As a video seller, you may expect to see CPMs over $20. In order to receive those bids, you'll need to implement custom price buckets setting the [priceGranularity](/dev-docs/publisher-api-reference/setConfig.html#setConfig-Price-Granularity) object in the `setConfig` method.
8484

85-
For instructions and sample code, see [Custom Price Granularity Buckets
86-
](/dev-docs/examples/custom-price-buckets.html).
85+
For instructions and sample code, see [Custom Price Granularity Buckets](/dev-docs/examples/custom-price-buckets.html).
8786

8887
### 3. Request bids, build video URL
8988

9089
Next, we need to do the standard Prebid "add ad units and request bids" dance.
9190

9291
In the example below, our callback builds the video URL the player needs using the `buildVideoUrl` method from the Google Ad Manager ad server module that we built into our copy of Prebid.js in the **Prerequisites** section.
9392

94-
For more information, see the API documentation for [pbjs.adServers.dfp.buildVideoUrl](/dev-docs/publisher-api-reference/adServers.dfp.buildVideoUrl.html). Understanding the arguments to this method is *especially* important if you plan to pass any custom parameters to Google Ad Manager. The `params` key in the argument to `buildVideoUrl` supports all parameters from the [Google Ad Manager API](https://support.google.com/admanager/answer/1068325).
93+
For more information, see the API documentation for [pbjs.adServers.gam.buildVideoUrl](/dev-docs/publisher-api-reference/adServers.dfp.buildVideoUrl.html). Understanding the arguments to this method is *especially* important if you plan to pass any custom parameters to Google Ad Manager. The `params` key in the argument to `buildVideoUrl` supports all parameters from the [Google Ad Manager API](https://support.google.com/admanager/answer/1068325).
9594

9695
```javascript
9796
pbjs.que.push(function() {
@@ -106,7 +105,7 @@ pbjs.que.push(function() {
106105

107106
pbjs.requestBids({
108107
bidsBackHandler: function(bids) {
109-
var videoUrl = pbjs.adServers.dfp.buildVideoUrl({
108+
var videoUrl = pbjs.adServers.gam.buildVideoUrl({
110109
adUnit: videoAdUnit,
111110
params: {
112111
iu: '/19968336/prebid_cache_video_adunit'
@@ -120,12 +119,12 @@ pbjs.que.push(function() {
120119

121120
#### Notes on Prebid Cache
122121

123-
The VAST XML has to be cached somewhere because most video players can only work with a URL that returns VAST XML, not VAST directly. Some bidders cache the VAST XML on the server side, while others depend on Prebid.js to perform the caching.
122+
The VAST XML is typically cached somewhere because GAM expects a URL that returns VAST XML, not a VAST document directly (but see [using the local cache](#local-cache)). Some bidders cache the VAST XML on the server side, while others depend on Prebid.js to perform the caching.
124123

125124
* In general, video-enabled bidders must supply `bid.videoCacheKey`, `bid.vastXml`, or `bid.vastUrl` on their responses, and can provide any combination of the three.
126-
* If `pbjs.setConfig({cache: {URL}})` isn't set and the bidder supplies only `bid.vastXml` in its bid response, [`pbjs.adServers.dfp.buildVideoUrl`](/dev-docs/publisher-api-reference/adServers.dfp.buildVideoUrl.html) will not be able to generate a videoCacheKey, and it will be dropped from the auction.
125+
* If `pbjs.setConfig({cache: {URL}})` isn't set and the bidder supplies only `bid.vastXml` in its bid response, [`pbjs.adServers.gam.buildVideoUrl`](/dev-docs/publisher-api-reference/adServers.gam.buildVideoUrl.html) will not be able to generate a videoCacheKey, and it will be dropped from the auction.
127126
* If `pbjs.setConfig({cache: {URL}})` is defined and the bidder responds with `bid.videoCacheKey`, Prebid.js will not re-cache the VAST XML.
128-
* If `options.url` is passed as an argument to [`pbjs.adServers.dfp.buildVideoUrl`](/dev-docs/publisher-api-reference/adServers.dfp.buildVideoUrl.html):
127+
* If `options.url` is passed as an argument to [`pbjs.adServers.gam.buildVideoUrl`](/dev-docs/publisher-api-reference/adServers.gam.buildVideoUrl.html):
129128
* If Prebid Cache is disabled, Prebid sets `description_url` field to the bid response's `bid.vastUrl`.
130129
* If Prebid Cache is enabled, Prebid sets `description_url` field to the cache URL.
131130

@@ -136,7 +135,7 @@ Display banners are rendered with the help of the renderAd function. This functi
136135
```javascript
137136
pbjs.requestBids({
138137
bidsBackHandler: function(bids) {
139-
var videoUrl = pbjs.adServers.dfp.buildVideoUrl({
138+
var videoUrl = pbjs.adServers.gam.buildVideoUrl({
140139
adUnit: videoAdUnit,
141140
params: {
142141
iu: '/19968336/prebid_cache_video_adunit'
@@ -145,7 +144,7 @@ pbjs.requestBids({
145144

146145
// Mark the bid, used in buildVideoUrl, as used
147146
pbjs.markWinningBidAsUsed({
148-
adUnitCode: videoAdUnit.code // optional if you know the adId
147+
adUnitCode: videoAdUnit.code, // optional if you know the adId
149148
adId: bid.adId // optional
150149
});
151150

@@ -189,6 +188,63 @@ In the body of the page, the following HTML and JS will show the ad:
189188

190189
If you have [set up your ad server line items and creatives correctly]({{site.baseurl}}/adops/setting-up-prebid-video-in-dfp.html), you should see an instream pre-roll video ad followed by the oceans video from the [video.js homepage](https://videojs.com/).
191190

191+
<a id="local-cache"></a>
192+
193+
### 5. Using the local cache
194+
195+
Since version 10.23 it is possible to work around GAM's requirement for a cached VAST URL by using a combination of [client side caching](/dev-docs/publisher-api-reference/setConfig.html#client-side-caching-of-vast-xml) and [`getVastXml`](/dev-docs/publisher-api-reference/adServers.gam.getVastXml.html). This uses the same setup described above, except that the cache is set to local:
196+
197+
```javascript
198+
pbjs.setConfig({
199+
cache: {
200+
useLocal: true
201+
}
202+
});
203+
```
204+
205+
And passing a VAST document directly to the player (instead of an ad tag URL). Using VideoJS:
206+
207+
```javascript
208+
function invokeVideoPlayer() {
209+
videojs("vid1").ready(function() {
210+
this.vastClient({
211+
adTagXml: function(callback) {
212+
pbjs.adServers.gam.getVastXml({
213+
adUnit: videoAdUnit,
214+
params: {
215+
iu: '/19968336/prebid_cache_video_adunit'
216+
}
217+
}).then(function(vastXml) {
218+
callback(null, vastXml);
219+
})
220+
},
221+
playAdAlways: true,
222+
verbosity: 0,
223+
vpaidFlashLoaderPath: "https://github.com/MailOnline/videojs-vast-vpaid/blob/RELEASE/bin/VPAIDFlash.swf?raw=true",
224+
autoplay: true
225+
});
226+
this.muted(true);
227+
this.play();
228+
});
229+
}
230+
```
231+
232+
See [below](#examples) for more examples.
233+
234+
The way this works is:
235+
236+
* when Prebid receives a video bid, it stores its VAST document in the browser as a [blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob), and updates its `.videoCacheKey` with the ID of that blob;
237+
* `getVastXml` first makes a request to GAM (using the URL returned by `getVideoUrl`);
238+
* If a Prebid bid wins the GAM auction (and the line items are set up as described in [GAM Step by Step - Video Creatives](/adops/setting-up-prebid-video-in-dfp.md)), the response will contain a VAST URL with a cache key that matches a blob ID;
239+
* `getVastXml` scans the response for such URLs, and replaces them with an inlined copy of the matching VAST XML from blob storage.
240+
241+
This means that you can migrate an existing setup using a 3rd party cache service to local caching without any changes in GAM (the VAST URLs in GAM creatives are ignored except for the cache key portion).
242+
243+
{: .alert.alert-warning :}
244+
Video players often add signals to the GAM ad tag URL. They cannot do this when using `getVastXml`, as there is no URL to augment. This can impact the GAM auction; in practice, this means that using client-side caching will likely result in lower AdX demand.
245+
246+
<a id="examples"></a>
247+
192248
## Working Examples
193249

194250
**Note:** Prebid video is designed to work across devices and browsers. This demo has been developed and tested only for Chrome desktop, Firefox desktop, and Chrome Android; additional device/browser support is planned to be added at a later date.

0 commit comments

Comments
 (0)