1. Help Center
  2. HB Manager
  3. Applications & Use-cases

Modify / Enrich pbjs.adUnit Object 1: Edit Bidder Parameters

onAuctionInitDone

Overview

This article outlines a method by which a publisher can modify the pbjs.adUnit object for any given bidder, for example to pass bidder parameters that are not commonly used or are tied to data available on the publishers site.

In this example we can use the onAuctionInitDone callback, invoked once all the placements are setup and before the auction has commenced, to intercept the pbjs.adUnit object that will be set and modify it.

In the example below we push custom placement data 'keywords' to the appneuxs 'keywords' bid parameter.

Code

relevantDigital.addAuctionCallbacks({
    onAuctionInitDone: ({ auction }) => {
        auction.usedUnitDatas.forEach((unitData) => {
            const { adUnit, pbAdUnit } = unitData;
          const value = adUnit.data.keywords;
          if (value) {
                pbAdUnit.bids.forEach((bid) => {
                  if (bid.bidder === "appnexus") {
                      bid.params.keywords = {"key": value}
                    }
                })
            }
        })
    },
})

Walk-through

Opposed to demonstrating the usecase in relevantDigital.loadPrebid(), the code is using relevantDigital.addAuctionCallbacks instead. The addAuctionCallbacks function is useful for implementing callback functions in scenarios where it may not be possible to edit relevantDigital.loadPrebid(). 

onAuctionInitDone callback is invoked once all the placements are setup and before the auction has commenced, to intercept the pbjs.adUnit object that will be set and modify it. onAuctionInitDone exposes an 'auction' object, from which we can retrieve 'adUnit' & 'pbAdUnit' data. 

The 'adUnit' data is all the information on the placement that is set in the Relevant Yield UI. This then includes any 'custom' data that may have been assigned to the placement through the use of the placement tag fields.

The 'pbAdUnit' data is essentially what will become the pbjs.adUnit object, the object that is required by pbjs for a placement to be included in the prebid auction. 

In the above example we retrieve 'keywords' custom data from the adUnit.data, and then appned it to the pbAdUnit if certain conditions are met.

These conditions are that pbAdUnit.bid.bidder is appnexus & adUnit.data.keywords is defined. 

If these conditions are met then 'value' (the custom data of adUnit.data.keywords) is appended to the bid.params for that given bidder (appnexus) in the auction.