Search code examples
google-dfp

registering to events with google publisher tag


according to the documentation at https://developers.google.com/doubleclick-gpt/reference#googletag.events.SlotRenderEndedEvent

there should be a way to register to an event that a tag was rendered:

Class googletag.events.SlotRenderEndedEvent

This event is fired when a slot on the page has finished rendering.

but when i inspected the dfp object i don't see any event namespace

enter image description here

any idea how to register to this event?


Solution

  • To register the event, use the following code:

    <script type='text/javascript'>
      googletag.cmd.push(function() { 
        googletag.defineSlot('/123456/leadeboard', [[728, 90]], 'div-gpt-ad-123456789-0').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest(); 
        googletag.pubads().addEventListener('slotRenderEnded', function(event) {
          console.log('Slot has been rendered:');
        });
        googletag.enableServices();
      });
    </script>
    

    The documentation is found in the GPT reference.