Füge Platzhalter für Propeller-Anzeigen hinzu und verbessere das Skript-Rendering

This commit is contained in:
Torsten Schulz (local)
2026-05-18 15:48:40 +02:00
parent 53a8aa3869
commit fdeecec63e

View File

@@ -34,6 +34,9 @@ const sticky = (import.meta.env.VITE_HEADER_STICKY || 'true') === 'true';
// Debug bypass: allow forcing ad load with ?ads_debug=1 // Debug bypass: allow forcing ad load with ?ads_debug=1
const debugForceLoad = typeof window !== 'undefined' && new URLSearchParams(window.location.search).get('ads_debug') === '1'; const debugForceLoad = typeof window !== 'undefined' && new URLSearchParams(window.location.search).get('ads_debug') === '1';
// Auto load flag (env) - set to 'true' to load ads on mount without waiting for interaction
const autoLoad = (import.meta.env.VITE_PROP_AUTOLOAD || 'true') === 'true';
// A/B test config // A/B test config
const abRatio = Number(import.meta.env.VITE_AB_RATIO || '50'); // percent for variant B const abRatio = Number(import.meta.env.VITE_AB_RATIO || '50'); // percent for variant B
@@ -99,6 +102,11 @@ async function renderPropeller() {
return; return;
} }
// create placeholder first and insert into ad container
const placeholder = document.createElement('div');
placeholder.className = 'propeller-ad-placeholder';
adContainer.value.appendChild(placeholder);
const s = document.createElement('script'); const s = document.createElement('script');
s.dataset.zone = propSlotId; s.dataset.zone = propSlotId;
s.src = propScriptUrl; s.src = propScriptUrl;
@@ -111,16 +119,8 @@ async function renderPropeller() {
try { window.dispatchEvent(new CustomEvent('ads:load-failed', { detail: { provider: 'propeller', zone: propSlotId, error: String(e) } })); } catch {} try { window.dispatchEvent(new CustomEvent('ads:load-failed', { detail: { provider: 'propeller', zone: propSlotId, error: String(e) } })); } catch {}
}; };
// Append to the document (documentElement or body) like the snippet does // Append the script directly into the placeholder so the provider injects into it
const target = [document.documentElement, document.body].filter(Boolean).pop(); placeholder.appendChild(s);
if (target) target.appendChild(s);
// Clear container so the ad can render without duplicates
adContainer.value.innerHTML = '';
// Propeller will usually inject the ad into the page; keep a placeholder node
const placeholder = document.createElement('div');
placeholder.className = 'propeller-ad-placeholder';
adContainer.value.appendChild(placeholder);
// Observe the document for injected ad nodes and relocate them into our placeholder // Observe the document for injected ad nodes and relocate them into our placeholder
const observeAndRelocate = () => { const observeAndRelocate = () => {