🛠️Customization
This section details how to customize the Header Bidding wrapper using custom scripts and modules, for Prebid 10 and later.
In plain terms: beyond the settings in Configuration, you can add your own JavaScript that becomes part of the wrapper build. This is for developers who need behaviour that settings alone can't express. If you're not writing code, you can skip this page.
Two ways to reach the wrapper — and when to use each:
From a custom script built into the wrapper (this page): read the global variable name from the config, since the script runs inside the wrapper's own environment. That's the
var pbjs = window[config.globalVar]pattern shown below.From a snippet on the publisher's page (see Public API): just use the global variable directly by name —
pbjsby default, or whatever your site sets inconfig.globalVar.
Both approaches talk to the same object; they only differ in how they get a reference to it. Neither uses the old $$PREBID_GLOBAL$$ macro, which was removed in Prebid 10.
Overview
Write modular scripts using the
custom_[name].jsconventionUse the configured wrapper global from
config.jsoninstead of the deprecated$$PREBID_GLOBAL$$macroPrefer queueing code that interacts with the wrapper API
CRITICAL: From 7.22.0, a throw while a custom_*.js file is loading no longer takes down the wrapper — but that custom script is skipped. Always wrap wrapper API calls (getUserInfo, getConfig, setConfig, aliasBidder, onEvent, and similar) in pbjsInstance.cmd.push(function() { ... }). Do not call them at the top of the file. Failed scripts log [wrapper] custom script failed: <filename> in the console.
Custom Script Files
Custom script/modules files can be loaded and concatenated to the core code. For the file to be parsed it needs to have the name with following syntax: custom_[filename].js
e.g.: custom_interstitial.js
It will always start with custom_ and the code needs to be written in javascript.
Any valid javascript is allowed.
Can import any module.
Must reference the Prebid instance via the wrapper configuration instead of the $$PREBID_GLOBAL$$ macro (removed in Prebid 10).
Accessing the Prebid Global (Prebid 10+)
Custom scripts run inside the wrapper environment. To access the Prebid instance in a way that is compatible with Prebid 10 and later, read the wrapper configuration and create a local reference:
You can then safely queue commands on pbjsInstance.cmd, for example to define an alias:
Executing Code After Page Load
Import docReady from _utils.js to run code after the DOM is ready. It is not attached to window.
Including Source Files
You can import modules from the src directory into your custom scripts. However, because of the build process, the relative path to these files will be one level deeper than it appears in the source tree. For example, to import utils.js from the src folder, you would use ../utils.js.
Example
Here is an example of a custom script that uses docReady from _utils.js, an import from the src directory, and the wrapper configuration to access the Prebid instance:
Last updated