registering to events with google publisher tag

Amir picture Amir · Jul 17, 2014 · Viewed 8.5k times · Source

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?

Answer

Codo picture Codo · Jul 19, 2014

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.