Google Publisher Tag registering to Events

一笑奈何 提交于 2019-12-04 19:19:14

Nastasja,

The reason the output repeats three times is the event handler that you registered listens for the 'slotRenderEnded' event, which happens every time a slot renders. Since your example has three slots, the event will fire three times. You can see which slot triggers the callback by inspecting the event object that is passed in.

 googletag.pubads().addEventListener('slotRenderEnded', function(event) {
        console.log('Slot has been rendered:');
        console.log(event); //inspect event
        console.log(event.slot); //inspect slot
 });

Even though the the event first three times, you can add slot based logic by comparing the slots in the event like this:

 var slot1 = googletag.defineSlot('/123456/leadeboard', [[728, 90]], 'div-gpt-ad-123456789-0').addService(googletag.pubads());
 googletag.pubads().addEventListener('slotRenderEnded', function(event) {
    if(slot1 === event.slot){
        console.log('slot1 has been rendered');
    }
 });

You can read more in the GPT documentation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!