DFP post-rendering callback

Sp4cecat picture Sp4cecat · Jun 27, 2012 · Viewed 28.2k times · Source

I need to trigger some JavaScript after DFP has finished rendering all the ads on the page - or at least when it has triggered collapseEmptyDivs (which hides ad units that contain no line items).

Is anyone aware of a way to get DFP to trigger a callback after either of these events?

Answer

z12345 picture z12345 · Apr 1, 2014

The GPT API now has a callback that is triggered after each slot is filled.

For example:

googletag.pubads().addEventListener('slotRenderEnded', function(event) {
 console.log('Creative with id: ' + event.creativeId +
  ' is rendered to slot of size: ' + event.size[0] + 'x' + event.size[1]);
});

See https://developers.google.com/doubleclick-gpt/reference#googletag.events.SlotRenderEndedEvent