fix(js): only use data-ad-status to determine slot fill state
AdSense injects iframe BEFORE setting data-ad-status, so using iframe presence as fill indicator causes false positives. Slots with unfilled ads were incorrectly marked as filled because iframe was detected first. Now only data-ad-status is used for final state determination. If data-ad-status is not yet set, the MutationObserver continues waiting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -305,35 +305,30 @@
|
||||
* @returns {boolean} true si el estado fue determinado (filled o empty)
|
||||
*/
|
||||
function checkFillStatus(slot, ins) {
|
||||
// Criterio 1: data-ad-status attribute
|
||||
// IMPORTANTE: Solo data-ad-status es confiable para determinar el estado final.
|
||||
// AdSense inyecta iframe ANTES de establecer data-ad-status, por lo que
|
||||
// la presencia de iframe NO indica que el anuncio fue llenado.
|
||||
|
||||
var status = ins.getAttribute('data-ad-status');
|
||||
|
||||
// Estado definitivo: filled
|
||||
if (status === 'filled') {
|
||||
debugLog('Slot llenado (data-ad-status=filled)');
|
||||
markSlotFilled(slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Estado definitivo: unfilled (sin anuncio disponible)
|
||||
if (status === 'unfilled') {
|
||||
debugLog('Slot vacio (data-ad-status=unfilled)');
|
||||
markSlotEmpty(slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Criterio 2 (fallback): iframe presente
|
||||
var iframe = ins.querySelector('iframe');
|
||||
if (iframe) {
|
||||
debugLog('Slot llenado (iframe detectado)');
|
||||
markSlotFilled(slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Criterio 3 (fallback): div con id presente
|
||||
var divWithId = ins.querySelector('div[id]');
|
||||
if (divWithId) {
|
||||
debugLog('Slot llenado (div con id detectado)');
|
||||
markSlotFilled(slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Si no hay data-ad-status, AdSense aun no ha respondido.
|
||||
// NO usar iframe como criterio porque AdSense inyecta iframe incluso para unfilled.
|
||||
// El MutationObserver seguira observando hasta que data-ad-status aparezca o timeout.
|
||||
debugLog('Esperando data-ad-status...');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user