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);
}
}
}
});
}