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

Google OutOfPage Setup (OOP)

onBeforeAuctionSetup & googletagCalls

Overview

This article outlines a method by which a publisher can transform a placement into a googletag out-of-page format. 

By default, when using Google AdManager Adserver, placements setup in Relevant yield are by default set using the standard googletag.defineSlot()

Using the onBeforeAuctionSetup callback and googletagCalls object available in the relevantDigital.loadPrebid() function a publisher can intercept the default googletag.defineSlot() behavior and impose googletag.defineOutOfPageSlot() instead.

Code

relevantDigital.addAuctionCallbacks({
    onBeforeAuctionSetup: ({ auction }) => {
        auction.googletagCalls = auction.googletagCalls || {};
        auction.googletagCalls.defineSlot = function (adUnitPath, size, div) {

            var elm = document.getElementById(div);

          //retrieve page identifier of the slot being OOP, in this case the value of "data-dfp-oop".
          var format = elm && elm.getAttribute('data-dfp-oop');
           
            if (format === 'outOfPage' || format === 'homepageOutOfPage' ) {
              return googletag.defineOutOfPageSlot(adUnitPath, div);
            }
          return googletag.defineSlot(adUnitPath, size, div); // Do the actual call
        }
    }
});

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(). 

onBeforeAuctionSetup is a function invoked before starting the auction that yields an auction object & divAttribute string. We are interested in the auction object here, and specifically adding the 'googletagCalls' object to auction object. 

We can create googletagCalls.defineSlot to intercept the defineSlot function and replace it with a modified version. 

The modified version maintains the same slot parameters as the original (adUnitPath, size, div). The div param is used to retrieve the html element of the adSlot (document.getElementById), and more specifically an attribute that distinguishes it as being destined for an OOP format (elm.getAttribute('data-dfp-oop')). The assumption here is that the publisher has added a method to identify the unit as being out-of-page on the site itself. 

If the value of the attribute corresponds to what we are looking for ( format === 'outOfPage' || format === 'homepageOutOfPage') then googletag.defineSlot is replaced with googletag.defineOutOfPageSlot(adUnitPath, div). 

At the end we return the googletag.defineSlot() so that googletagCalls.defineSlot() recieves the slot object created by gpt.