Back to Publisher API Reference

pbjs.renderBid(bid, options)

Since Prebid.js 11.51, render a bid in an isolated iframe inside its ad unit’s element, without an ad server’s on-page library (such as GPT) handling rendering. Requires the Safe Rendering module.

Kind: static method of pbjs API

The contents of the bid’s element are replaced with a single iframe, and the ad is rendered inside it. The frame has an opaque origin and the same sandbox attribute as Google Ad Manager’s SafeFrames, so the creative can’t reach the publisher’s page. The element is the ad unit’s element, or document.getElementById(adUnitCode) by default. It must belong to the document of the window that loaded Prebid.js, or of a same-origin iframe nested inside it.

Param Scope Type Description
bid Required object The bid to render, for example one returned by getHighestCpmBids. Only its adId is used.
options Optional object The same options as renderAd (listed below).
options.clickThrough Optional string A URL used to resolve the ${CLICKTHROUGH} macro in the ad markup.
options.viewUrl Optional string The ad server’s view-tracking URL. Prebid.js stores it on the rendered bid as bid.viewUrl but does not fire it.

Example:

pbjs.requestBids({
  bidsBackHandler: function () {
    pbjs.getHighestCpmBids().forEach(function (bid) {
      pbjs.renderBid(bid);
    });
  }
});

If the render can’t start, renderBid emits adRenderFailed; see the Safe Rendering module for the reasons and other limitations.

Back to Publisher API Reference