1

I'm using googletag.pubads().refresh([currentAdSlot]) in infinite loop by scrolling mouse window down and i want to listen 'slotRenderEnded' event after refresh function. But each when i call refresh function, 'slotRenderEvent' triggered cumulatively. For example at the first call ResendAd function, listening event working just one time. At the seconds call, listening event working two time and continuously increase this count. How to fix this bug? I don't understand what's wrong? It's google dfp api's bug or my code?

function ResendAd(AdSlot,callback) {

  googletag.pubads().clearTargeting();
  googletag.pubads().updateCorrelator();
  googletag.pubads().refresh([AdSlot]);

  googletag.pubads().addEventListener('slotRenderEnded', function (event) {
    console.warn('This function scope triggered multiple times.');
    if (event.slot === AdSlot) {
      if (!event.isEmpty) {
        if (callback && typeof callback === "function") {
          callback(event);
        }
      }
    }
  });
}
kenanyildiz90
  • 176
  • 3
  • 13

1 Answers1

3

It's a bug in your code. Every time you call ResendAd, you are adding an event listener (slotRenderEnded).

You should add the event listener in a function that's only called once. I can't tell you where exactly as I don't have access to your code.

yvanavermaet
  • 348
  • 1
  • 9