Aktualisiere HeaderAdBanner-Komponente mit Standardwerten für Propeller-Anzeigen und verbessere die Skriptintegration

This commit is contained in:
Torsten Schulz (local)
2026-05-18 15:12:35 +02:00
parent 44dd757243
commit 0f6ba9222b
2 changed files with 31 additions and 15 deletions

View File

@@ -1,3 +1,11 @@
Aktuell habe ich das InPage Push Snippet, das du gepostet hast, als Default eingebaut:
```html
<script>(function(s){s.dataset.zone='11023637',s.src='https://nap5k.com/tag.min.js'})([document.documentElement, document.body].filter(Boolean).pop().appendChild(document.createElement('script')))</script>
Das ist jetzt die StandardKonfiguration in `HeaderAdBanner.vue` wenn `VITE_AD_PROVIDER=propeller` ist. Du kannst die Werte via Env überschreiben:
- `VITE_PROP_SCRIPT_URL` (default `https://nap5k.com/tag.min.js`)
- `VITE_PROP_SLOT` (default `11023637`)
Wenn du später ein anderes Format/Zone anlegen willst, gib mir die neue ZoneID oder das komplette Snippet, dann passe ich es an.
Live testen (empfohlen): kopiere die Datei in dein ProduktionsDokumentRoot so, dass sie unter `https://yourdomain/scripts/sw.js` erreichbar ist. In diesem Repo habe ich die Datei zusätzlich ins ProjektRoot (`/sw.js`) und in [docroot/sw.js](docroot/sw.js) gelegt. Live testen (empfohlen): kopiere die Datei in dein ProduktionsDokumentRoot so, dass sie unter `https://yourdomain/scripts/sw.js` erreichbar ist. In diesem Repo habe ich die Datei zusätzlich ins ProjektRoot (`/sw.js`) und in [docroot/sw.js](docroot/sw.js) gelegt.
Live testen (empfohlen): kopiere die Datei in dein ProduktionsDokumentRoot so, dass sie unter `https://yourdomain/sw.js` erreichbar ist (Root Pfad). In diesem Repo habe ich die Datei zusätzlich ins ProjektRoot (`/sw.js`) und in [docroot/sw.js](docroot/sw.js) gelegt. Live testen (empfohlen): kopiere die Datei in dein ProduktionsDokumentRoot so, dass sie unter `https://yourdomain/sw.js` erreichbar ist (Root Pfad). In diesem Repo habe ich die Datei zusätzlich ins ProjektRoot (`/sw.js`) und in [docroot/sw.js](docroot/sw.js) gelegt.

View File

@@ -17,8 +17,9 @@ const adClient = import.meta.env.VITE_ADSENSE_CLIENT || '';
const adSlot = import.meta.env.VITE_ADSENSE_HEADER_SLOT || ''; const adSlot = import.meta.env.VITE_ADSENSE_HEADER_SLOT || '';
// Propeller config: you can set the script URL and the slot id via env // Propeller config: you can set the script URL and the slot id via env
const propScriptUrl = import.meta.env.VITE_PROP_SCRIPT_URL || ''; // Defaults set to the in-page push tag you provided (can be overridden via env)
const propSlotId = import.meta.env.VITE_PROP_SLOT || ''; const propScriptUrl = import.meta.env.VITE_PROP_SCRIPT_URL || 'https://nap5k.com/tag.min.js';
const propSlotId = import.meta.env.VITE_PROP_SLOT || '11023637';
// Show only if the selected provider has config // Show only if the selected provider has config
const isEnabled = computed(() => { const isEnabled = computed(() => {
@@ -89,20 +90,27 @@ function ensureScriptLoaded(src, attrName) {
async function renderPropeller() { async function renderPropeller() {
if (!adContainer.value) return; if (!adContainer.value) return;
try { try {
await ensureScriptLoaded(propScriptUrl, 'propeller'); // Insert Propeller in-page push tag exactly as provided by PropellerAds.
// Provider-specific insertion: Propeller usually exposes a global builder or expects a div with an id. // Avoid duplicate insertion if same script+zone already present.
// We create a lightweight iframe fallback that publishers can map on Propeller dashboard by slot id. if (document.querySelector(`script[src="${propScriptUrl}"][data-zone="${propSlotId}"]`)) {
const iframe = document.createElement('iframe'); return;
iframe.width = '100%'; }
iframe.height = '90';
iframe.frameBorder = '0'; const s = document.createElement('script');
iframe.scrolling = 'no'; s.dataset.zone = propSlotId;
iframe.style.border = '0'; s.src = propScriptUrl;
iframe.title = 'Advertisement'; s.async = true;
// Minimal message to the ad server; the exact ad markup is controlled via the external propeller script/endpoint.
iframe.src = `${propScriptUrl}?slot=${encodeURIComponent(propSlotId)}&responsive=1`; // Append to the document (documentElement or body) like the snippet does
const target = [document.documentElement, document.body].filter(Boolean).pop();
if (target) target.appendChild(s);
// Clear container so the ad can render without duplicates
adContainer.value.innerHTML = ''; adContainer.value.innerHTML = '';
adContainer.value.appendChild(iframe); // 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);
} catch (err) { } catch (err) {
console.warn('Propeller ad load failed', err); console.warn('Propeller ad load failed', err);
} }