Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

registering to events with google publisher tag

Tags:

google-dfp

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?

like image 333
Amir Avatar asked Jul 16 '14 23:07

Amir


People also ask

What is a Google Publisher Tag?

Google Publisher Tag (GPT) is an ad tag library that allows publishers to define inventory, initiate and bundle ad requests, and render matching demand. GPT takes key details from you (such as ad unit code, ad size, and key-values), builds the request, and displays the ad on web pages.

How do I enable the Google Publisher Console?

Other options to open the Publisher ConsoleAfter loading the page, enter javascript: googletag. openConsole() in your browser's JavaScript console and run the code. Developer Tools. Click Console.

What is Googletag defineSlot?

googletag.Constructs an ad slot with a given ad unit path and size and associates it with the ID of a div element on the page that will contain the ad. Example. googletag. defineSlot('/1234567/sports', [728, 90], 'div-1'); See also.


1 Answers

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.

like image 186
Codo Avatar answered Oct 23 '22 01:10

Codo