forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing prebid-cache to support Video ads (prebid#1277)
* Added code to cache video content, and made the cache key accessible through the bid. * Renamed the method we add to the bid. * Removed an extraneous function. * Removed some accidental console.log messages * Added unit tests for the video cache, and fixed a bug or two. * Refactored the bidmanager a bit to help wrap my head around it, and changed video support so that only bids which have been cached are valid. * Implemented video end-to-end. Waiting on the modules PR so that it can be transformed into a module. * Better fix to the utils bug. Modernized the imports. * Updated documentation. * Added a few unit tests, and added fixtures for shared data structures. * Added more thorough tests, and refactored a bit for better code reuse. * Renamed a function. * Added tests for adding video bids when the cache fails. * Removed an unused import. * Added tests for the adServerManager, and renamed some files for consistency with the normal conventions. * Renamed the dfpVideo module, and added unit tests for it. * Moved dfpAdServerVideo into the modules directory. * Fixed a bug, and added a regression test to catch it in the future. * Added a bare-bones example page. * Made some cosmetic changes to names and documentation. * Removed the shifty API. Updated unit tests. Renamed a property because Ive messed it up multiple times myself already during testing, expecting it to have a different name. * Most code review comments. Still need to look into the details of VAST. * Deleted some unused code, and upped the vast version to use 3.0 everywhere. * Made the cache use the new endpoints * Fixed style. * Moved the test page into the tests directory. * include the bid that ended the auction
- Loading branch information
1 parent
62e4959
commit dc7b858
Showing
15 changed files
with
929 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* This module adds [DFP support]{@link https://www.doubleclickbygoogle.com/} for Video to Prebid. | ||
*/ | ||
|
||
import { registerVideoSupport } from '../src/adServerManager'; | ||
import { getWinningBids } from '../src/targeting'; | ||
import { formatQS, format as buildUrl } from '../src/url'; | ||
import { parseSizesInput } from '../src/utils'; | ||
|
||
/** | ||
* @typedef {Object} DfpVideoParams | ||
* | ||
* This object contains the params needed to form a URL which hits the | ||
* [DFP API]{@link https://support.google.com/dfp_premium/answer/1068325?hl=en}. | ||
* | ||
* All params (except iu, mentioned below) should be considered optional. This module will choose reasonable | ||
* defaults for all of the other required params. | ||
* | ||
* The cust_params property, if present, must be an object. It will be merged with the rest of the | ||
* standard Prebid targeting params (hb_adid, hb_bidder, etc). | ||
* | ||
* @param {string} iu This param *must* be included, in order for us to create a valid request. | ||
* @param [string] description_url This field is required if you want Ad Exchange to bid on our ad unit... | ||
* but otherwise optional | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} DfpVideoOptions | ||
* | ||
* @param {Object} adUnit The adUnit which this bid is supposed to help fill. | ||
* @param [Object] bid The bid which should be considered alongside the rest of the adserver's demand. | ||
* If this isn't defined, then we'll use the winning bid for the adUnit. | ||
* | ||
* @param {DfpVideoParams} params Query params which should be set on the DFP request. | ||
* These will override this module's defaults whenever they conflict. | ||
*/ | ||
|
||
/** Safe defaults which work on pretty much all video calls. */ | ||
const defaultParamConstants = { | ||
env: 'vp', | ||
gdfp_req: 1, | ||
output: 'xml_vast3', | ||
unviewed_position_start: 1, | ||
}; | ||
|
||
/** | ||
* Merge all the bid data and publisher-supplied options into a single URL, and then return it. | ||
* | ||
* @see [The DFP API]{@link https://support.google.com/dfp_premium/answer/1068325?hl=en#env} for details. | ||
* | ||
* @param {DfpVideoOptions} options Options which should be used to construct the URL. | ||
* | ||
* @return {string} A URL which calls DFP, letting options.bid | ||
* (or the auction's winning bid for this adUnit, if undefined) compete alongside the rest of the | ||
* demand in DFP. | ||
*/ | ||
export default function buildDfpVideoUrl(options) { | ||
const adUnit = options.adUnit; | ||
const bid = options.bid || getWinningBids(adUnit.code)[0]; | ||
|
||
const derivedParams = { | ||
correlator: Date.now(), | ||
sz: parseSizesInput(adUnit.sizes).join('|'), | ||
url: location.href, | ||
}; | ||
|
||
const customParams = Object.assign({}, | ||
bid.adserverTargeting, | ||
{ hb_uuid: bid.videoCacheKey }, | ||
options.params.cust_params); | ||
|
||
const queryParams = Object.assign({}, | ||
defaultParamConstants, | ||
derivedParams, | ||
options.params, | ||
{ cust_params: encodeURIComponent(formatQS(customParams))}); | ||
|
||
return buildUrl({ | ||
protocol: 'https', | ||
host: 'pubads.g.doubleclick.net', | ||
pathname: '/gampad/ads', | ||
search: queryParams | ||
}); | ||
} | ||
|
||
registerVideoSupport('dfp', { | ||
buildVideoUrl: buildDfpVideoUrl | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { getGlobal } from 'src/prebidGlobal'; | ||
import { logWarn } from 'src/utils'; | ||
|
||
const prebid = getGlobal(); | ||
|
||
/** | ||
* This file defines the plugin points in prebid-core for AdServer-specific functionality. | ||
* | ||
* Its main job is to expose functions for AdServer modules to append functionality to the Prebid public API. | ||
* For a given Ad Server with name "adServerName", these functions will only change the API in the | ||
* $$PREBID_GLOBAL$$.adServers[adServerName] namespace. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} CachedVideoBid | ||
* | ||
* @property {string} videoCacheId The ID which can be used to retrieve this video from prebid-server. | ||
* This is the same ID given to the callback in the videoCache's store function. | ||
*/ | ||
|
||
/** | ||
* @function VideoAdUrlBuilder | ||
* | ||
* @param {CachedVideoBid} bid The winning Bid which the ad server should show, assuming it beats out | ||
* the competition. | ||
* | ||
* @param {Object} options Options required by the Ad Server to make a valid AdServer URL. | ||
* This object will have different properties depending on the specific ad server supported. | ||
* For more information, see the docs inside the ad server module you're supporting. | ||
* | ||
* @return {string} A URL which can be passed into the Video player to play an ad. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} VideoSupport | ||
* | ||
* @function {VideoAdUrlBuilder} buildVideoAdUrl | ||
*/ | ||
|
||
/** | ||
* Enable video support for the Ad Server. | ||
* | ||
* @property {string} name The identifying name for this adserver. | ||
* @property {VideoSupport} videoSupport An object with the functions needed to support video in Prebid. | ||
*/ | ||
export function registerVideoSupport(name, videoSupport) { | ||
prebid.adServers = prebid.adServers || { }; | ||
prebid.adServers[name] = prebid.adServers[name] || { }; | ||
if (prebid.adServers[name].buildVideoUrl) { | ||
logWarn(`Multiple calls to registerVideoSupport for AdServer ${name}. Expect surprising behavior.`); | ||
return; | ||
} | ||
prebid.adServers[name].buildVideoUrl = videoSupport.buildVideoUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.