2016-07-01 4 views
0

무한 루프에서 마우스 윈도우를 아래로 움직여 googletag.pubads(). refresh ([currentAdSlot])를 사용하고 있는데 ' slotRenderEnded '이벤트를 새로 고친 후. 하지만 각각 내가 새로 고침 기능을 호출 할 때 'slotRenderEvent'가 누적 적으로 트리거됩니다. 예를 들어 첫 번째 ResendAd 함수 호출에서 이벤트를 한 번만 듣고 있습니다. 초 단위 호출에서 이벤트를 두 번 듣고 계속이 카운트를 증가시킵니다. 이 버그를 수정하는 방법? 뭐가 잘못 됐는지 이해가 안돼? Google dfp api의 버그 또는 코드입니까?pubads(). refresh ([currentSlot])

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

답변

1

이것은 코드에 버그가 있습니다. ResendAd를 호출 할 때마다 이벤트 리스너 (slotRenderEnded)가 추가됩니다.

한 번만 호출되는 함수에 이벤트 리스너를 추가해야합니다. 내가 코드에 액세스 할 수없는 정확한 위치를 말할 수는 없습니다.