Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document pbjs.adServers.dfp.buildVideoUrl update to accept ad server URL #422

Merged
merged 5 commits into from
Nov 15, 2017
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 95 additions & 25 deletions dev-docs/publisher-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1232,47 +1232,42 @@ unsubscribe(); // no longer listening
### pbjs.adServers.dfp.buildVideoUrl(options) ⇒ `String`

{: .alert.alert-info :}
This method was added in 0.26.0. For a usage example and instructions showing how to build Prebid.js to include this method, see [Show Video Ads with DFP]({{site.baseurl}}/dev-docs/show-video-with-a-dfp-video-tag.html).
This method was added in [0.26.0](https://github.com/prebid/Prebid.js/releases/tag/0.26.0).

This method returns a DFP video ad tag URL which is built by combining publisher-provided URL parameters with Prebid.js key-values.
This method returns a DFP video ad tag URL. The tag is built by combining publisher-provided parameters with Prebid.js targeting parameters, and then used by your video player.

This method takes a single `options` object as an argument, described below:
For a longer usage example and instructions showing how to build Prebid.js to include this method, see [Show Video Ads with DFP]({{site.baseurl}}/dev-docs/show-video-with-a-dfp-video-tag.html).

{: .table .table-bordered .table-striped }
| Field | Type | Description |
|--------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| adUnit | object | (Required) The Prebid adUnit to which the returned URL will map. |
| bid | object | (Optional) The Prebid bid for which targeting will be set. If this is not defined, Prebid will use the bid with the highest CPM for the adUnit. |
| params | object | (Required) Querystring parameters that will be used to construct the DFP video ad tag URL. |

The `options.params` object is described below:
For more information, see the sections below.

{: .table .table-bordered .table-striped }
| Field | Type | Description | Example |
|----------------|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| iu | string | (Required) DFP adUnit ID. For more information, see the [DFP documentation on `iu`](https://support.google.com/dfp_premium/answer/1068325?hl=en#iu) | `/19968336/prebid_cache_video_adunit` |
| cust_params | object | (Optional) Key-value pairs that will be sent to DFP on the video ad tag URL. If present, any key-values here will be merged with Prebid standard targeting key-values. For more information, see the [DFP documentation on `cust_params`](https://support.google.com/dfp_premium/answer/1068325?hl=en#cust_params) | {section: "blog", anotherKey: "anotherValue"} |
| "arbitraryKey" | string | (Optional) Any additional querystring parameters that will be used to construct the DFP video ad tag URL. | `output: "vast"` |
+ [Examples](#buildVideoUrl-example-usage): *Code samples showing how to build a video ad tag URL*.
+ [The `options` object](#buildVideoUrl-options-object): *Field definitions for the method's only argument*.
+ [The `options.params` object](#buildVideoUrl-options-params): *Field definitions for the `options.params` sub-object*.
+ [Usage scenarios and expected behavior](#buildVideoUrl-usage-scenarios-and-expected-behavior): *How the method's different arguments interact with each other and your (optional) usage of the Prebid Cache*.

{: .alert.alert-info :}
Note: Prebid.js will choose reasonable default values for any required DFP URL parameters that are not included in the `options.params` object.
<a name="buildVideoUrl-example-usage" />

For more information about the options supported by the DFP API, see [the DFP API docs](https://support.google.com/dfp_premium/answer/1068325?hl=en#env).
#### Examples

#### Example Usage

For a usage example in context, see [Show Video Ads with DFP]({{site.baseurl}}/dev-docs/show-video-with-a-dfp-video-tag.html).
In this example, we use the [`options.params`](#buildVideoUrl-options-params) argument to build up the ad tag:

```javascript
/* Prebid Cache is enabled in this example. See elsewhere in this
section for how turning it off affects the usage of
`dfp.buildVideoUrl`. */
pbjs.setConfig({
usePrebidCache: true
});

pbjs.requestBids({
bidsBackHandler: function(bids) {
var videoUrl = pbjs.adServers.dfp.buildVideoUrl({
adUnit: videoAdUnit,
params: {
iu: '/19968336/prebid_cache_video_adunit',
cust_params: {
section: "blog",
anotherKey: "anotherValue"
section: "blog",
anotherKey: "anotherValue"
},
hl: "en",
output: "vast",
Expand All @@ -1290,4 +1285,79 @@ This call returns the following DFP video ad tag URL:
https://pubads.g.doubleclick.net/gampad/ads?env=vp&gdfp_req=1&output=vast&unviewed_position_start=1&correlator=1507127916397&sz=640x480&url=http://www.referer-url.com&iu=/19968336/prebid_cache_video_adunit&cust_params=hb_bidder%3DappnexusAst%26hb_adid%3D26d4996ee83709%26hb_pb%3D10.00%26hb_size%3D640x480%26hb_uuid%3D16c887cf-9986-4cb2-a02f-8e9bd025f875%26section%3Dblog%26anotherKey%3DanotherValue&hl=en
```

In this example, we use the [`options.url`](#buildVideoUrl-options-object) argument to pass in the video ad server directly:

```javascript
var adserverTag = 'https://pubads.g.doubleclick.net/gampad/ads?'
+ 'sz=640x480&iu=/19968336/prebid_video_adunit&impl=s&gdfp_req=1'
+ '&env=vp&output=xml_vast2&correlator=' + Date.now();

var videoUrl = pbjs.adServers.dfp.buildVideoUrl({
adUnit: videoAdUnit,
url: adserverTag
});
```

</div>

<a name="buildVideoUrl-options-object" />

#### The `options` object

The `options` object has the following fields:

{: .table .table-bordered .table-striped }
| Field | Type | Description |
|--------+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| adUnit | object | (Required) The Prebid adUnit to which the returned URL will map. |
| bid | object | (Optional) The Prebid bid for which targeting will be set. If this is not defined, Prebid will use the bid with the highest CPM for the adUnit. |
| params | object | (Required) Querystring parameters that will be used to construct the DFP video ad tag URL. Publisher-supplied values will override values set by Prebid.js. See below for fields. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that Options.params is required. It should be acceptable to invoke buildVideoUrl with an Options object that contains either the "url" or "params" field.

@matthewlane can we confirm the expected behavior if both Options.params and Options.url are passed to buildVideoUrl?

Copy link
Collaborator

@matthewlane matthewlane Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, options.params isn't required, the pub can pass either options.params, options.url, or both, but not neither.

If both params and url are passed in, the url is parsed, and any equivalent params that are present will overwrite those that were present in the url (in other words, in the event of collisions, params takes precedence). Then everything else that happens when just params were passed in still happens (adding defaults, adserver targeting, etc.), everything is stringified back to a url, and this is returned

| url | string | (Optional) The video ad server URL. When given alongside `params`, the parsed URL will be overwritten with any matching components of `params`. |

<a name="buildVideoUrl-options-params" />

#### The `options.params` object

The `options.params` object contains the parameters needed to form a URL which hits the [DFP API](https://support.google.com/dfp_premium/answer/1068325?hl=en). It has the following fields:

{: .table .table-bordered .table-striped }
| Field | Type | Description | Example |
|-------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------|
| iu | string | (Required) DFP adUnit ID. For more information, see the [DFP documentation on `iu`](https://support.google.com/dfp_premium/answer/1068325?hl=en#iu) | `/19968336/prebid_cache_video_adunit` |
| cust_params | object | (Optional) Key-value pairs merged with Prebid's targeting values and sent to DFP on the video ad tag URL. For more information, see the [DFP docs on `cust_params`](https://support.google.com/dfp_premium/answer/1068325?hl=en#cust_params) | `{section: "blog", anotherKey: "anotherValue"}` |
| `description_url` | string | (Optional) Describes the video. Required for Ad Exchange. Prebid.js will build this for you unless you pass it explicitly. | |

{: .alert.alert-info :}
Note: Prebid.js will choose reasonable default values for any required DFP URL parameters that are not included in the `options.params` object.

For more information about the options supported by the DFP API, see [the DFP API docs](https://support.google.com/dfp_premium/answer/1068325?hl=en#env).

<a name="buildVideoUrl-usage-scenarios-and-expected-behavior" />

#### Usage scenarios and expected behavior

How you call `dfp.buildVideoUrl` may change depending on:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to rework or possibly eliminate this section. Options.params and Options.url are not really intended for distinct sets of use-cases. We allow users to either pass an existing adserver URL or an object containing adserver URL querystring parameters for convenience.


+ Whether you pass in query string parameters via `options.params`, the ad server URL via `options.url`, or both.
+ Whether you choose to use Prebid Cache, a server-side asset cache hosted by Prebid.org.

Reasons you might pass the `options.url` field include:

- You are not using an ad server, and you want to insert the winning VAST content into your player directly
- You are using a video ad server that can accept a standalone VAST URL, as opposed to having to pass the VAST URL as a query string parameter

The table below lists the expected behavior of this method when called with various combinations of arguments and cache usage.

{: .table .table-bordered .table-striped }
Copy link
Contributor

@mjacobsonny mjacobsonny Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to figure out how to represent more clearly the information in the table below, as it seems a bit confusing to me at the moment.

| Argument | Prebid Cache Enabled? | Notes |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewlane based on your comment update re: how/when description_url gets built, I added some more info to this table. I also added two more lines for the "only using options.url cases with cache on/off.

Are the descriptions of what happens in each of these cases correct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmloveland One update for the notes in options.url only, cache enabled

Prebid attaches the bid’s adserver targeting and rebuilds the URL based on the input by merging publisher input with default values. It does not set description_url to bid.vastUrl.

default values aren't merged in this case, the resulting url is just based off the input url with adserver targeting attached.

All other descriptions look good to me

|------------------------------------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `options.params` only | Yes | None. |
| `options.params` only | No | Bidder's response must contain `bid.vastUrl` for video ad to serve. |
| `options.url` only | Yes | Prebid attaches the bid's adserver targeting and rebuilds the URL based on the input by merging publisher input with default values. It does not set `description_url` to `bid.vastUrl`. |
| `options.url` only | No | Bidder's response must contain `bid.vastUrl` for video ad to serve. Prebid sets `description_url` to `bid.vastUrl`. |
| `options.params` and `options.url` | Yes | Prebid attaches the bid's adserver targeting and rebuilds the URL based on the input by merging publisher input with default values. It does not set `description_url` to `bid.vastUrl`. |
| `options.params` and `options.url` | No | Bidder's response must contain `bid.vastUrl` for video ad to serve. |

{: .alert.alert-info :}
**Bid Responses and Prebid Cache**
Video bidders must supply either `bid.vastUrl` or `bid.vastXml`. They may supply both. If the video bidder supplies *only* `bid.vastXml` and Prebid Cache is disabled, this will not work and the bid will be dropped from the auction (if Prebid Cache is enabled, this same scenario is fine). If a video bidder supplies neither `bid.vastUrl` or `bid.vastXml`, the bid is dropped.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of the last sentence: "If a video bidder supplies neither bid.vastUrl or bid.vastXml, the bid is dropped.", as it seems repetitive.