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

Remove a size from Prebid Auction

onAuctionInitDone

Overview

This article outlines a method by which a publisher can remove a size from the prebid auction whilst maintaining that size in the call to the adserver. 

This example involves the use of the 'onAuctionInitDone' callback. A callback function invoked after  all the placements are setup but before the pbjs auction. 

Using the onBeforeAdRequest exposes the auction.usedUnitDatas object from which we can retrieve the adUnit information that will become the pbjs.adUnit object.

Code

relevantDigital.addAuctionCallbacks({
    onAuctionInitDone: function({ auction }) {
        auction.usedUnitDatas.forEach(({ pbAdUnit }) => {
            const { sizes } = (pbAdUnit.mediaTypes || {}).banner || {};
            const sizesToRemove = [[1,1]]
            if (sizes) {
                const newSizes = sizes.filter(size => {
                  return !sizesToRemove.some(([w, h]) => size[0] === w && size[1] === h);
              });
          
              if (newSizes.length > 0) {
                  pbAdUnit.mediaTypes.banner.sizes = newSizes;
                  if (pbAdUnit.sizes) {
                      pbAdUnit.sizes = newSizes;
                  }
              }
            }
        });
    },
  });

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 is a function invoked after the placement is setup and before the pbjs auction. It yields an auction object that contains a 'usedUnitDatas' array of objects that will participate in the auction. For each of these 'usedUnits' we would then like to retrieve the 'pbAdUnit' object.

The 'pbAdUnit' object exposes all the information on what the prebid AdUnit setup will be before it is  pushed to pbjs. 

From each 'pbAdUnit' we can retrieve the sizes from the  mediaTypes.banner and then we can define an array of 'sizesToRemove'.

If the sizes array is defined then a 'newSizes' array can be produced, filtering out the 'sizesToRemove' from 'sizes'.

'newSizes' array can then be pushed back to the pbAdUnit.mediaTypes.banner.sizes or pbAdUnit.sizes.