Füge Fallback-Logik für Anzeigen hinzu: Lade iframe-Backup, wenn nach 3s kein Ad im Platzhalter erscheint

This commit is contained in:
Torsten Schulz (local)
2026-05-18 15:38:32 +02:00
parent fbeda6a528
commit 12a724614d

View File

@@ -167,6 +167,33 @@ async function renderPropeller() {
// Start observing shortly after script insertion to allow provider to run
setTimeout(observeAndRelocate, 100);
// Fallback: wenn nach ScriptLoad innerhalb 3s kein Ad im Placeholder erscheint,
// lade ein iframeBackup. Das erhöht die Chance, ein sichtbares Banner im Header zu zeigen.
setTimeout(() => {
try {
const ph = adContainer.value.querySelector('.propeller-ad-placeholder');
const hasChild = ph && ph.children && ph.children.length > 0;
const height = ph ? parseInt(getComputedStyle(ph).height || '0', 10) : 0;
if (!hasChild && (!height || height === 0)) {
console.log('Ad placeholder empty — inserting iframe fallback');
const iframe = document.createElement('iframe');
iframe.width = '100%';
iframe.height = '90';
iframe.frameBorder = '0';
iframe.scrolling = 'no';
iframe.style.border = '0';
iframe.title = 'Advertisement';
// Fallback URL: attempt to call tag URL with slot param — may be accepted by provider
iframe.src = `${propScriptUrl}?slot=${encodeURIComponent(propSlotId)}&responsive=1`;
ph.innerHTML = '';
ph.appendChild(iframe);
try { window.dispatchEvent(new CustomEvent('ads:fallback-inserted',{detail:{provider:'propeller',zone:propSlotId}})); } catch {}
}
} catch (e) {
console.warn('Fallback insertion failed', e);
}
}, 3000);
} catch (err) {
console.warn('Propeller ad load failed', err);
}