Full-Page-Interstitial-Anzeigen in Single-Page-Anwendungen
VorherigeIntegration von ExoClick-Anzeigenzonen mit Vue.jsNächsteWie man SFW-Anzeigen mit ExoClick ausliefert
Zuletzt aktualisiert
War das hilfreich?
War das hilfreich?
'use client'
import { useEffect, useState } from 'react'
export default function HomePage() {
const [adLoaded, setAdLoaded] = useState(false)
const [currentPage, setCurrentPage] = useState('home')
useEffect(() => {
setAdLoaded(true)
console.log('✅ FPI-API-Methode initialisiert')
}, [])
}const triggerFPIAd = async () => {
console.log('🎯 Direkten API-Aufruf an den FPI-Dienst durchführen...')
try {
// Anfrage mit Benutzerkontext vorbereiten
const requestBody = {
user: {
ua: navigator.userAgent,
language: navigator.language || 'en-US',
referer: window.location.href,
consumer: 'ad-provider',
gdpr: { gdpr: 0 },
screen_resolution: `${screen.width}x${screen.height}`,
window_orientation: screen.width > screen.height ? 'landscape' : 'portrait',
cookies: [],
scr_info: btoa('async||3')
},
zones: [{
custom_targeting: {},
id: 1234567, // Ihre FPI-Zonen-ID (verwenden Sie für Mobilgeräte die mobile FPI-Zonen-ID)
extra_params: {
first_request: true,
zone_type: 35 // Interstitial-Format
}
}]
}
// API-Aufruf ausführen
const response = await fetch('https://s.pemsrv.com/v1/api.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody)
})
if (!response.ok) {
throw new Error(`HTTP-Fehler! Status: ${response.status}`)
}
const data = await response.json()
console.log('📥 Vollständige API-Antwort:', data)
// Antwort verarbeiten
if (data.zones && data.zones.length > 0) {
const zone = data.zones[0]
if (zone.data) {
console.log('🎨 Anzeige wird dargestellt...')
await displayInterstitialAd(zone.data)
} else {
console.log('❌ Keine Anzeigendaten in der Antwort')
}
}
} catch (error) {
console.error('❌ FPI-API-Fehler:', error)
}
}const displayInterstitialAd = async (adData: any) => {
console.log('🎨 Beginne mit der Anzeige der Interstitial-Anzeige...')
try {
// Vorhandenes Overlay entfernen
const existingOverlay = document.getElementById('fpi-interstitial-overlay')
if (existingOverlay) {
document.body.removeChild(existingOverlay)
}
// Vollbild-Overlay erstellen
const overlay = document.createElement('div')
overlay.id = 'fpi-interstitial-overlay'
overlay.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.9);
z-index: 999999;
display: flex;
align-items: center;
justify-content: center;
`
// Anzeigen-Container erstellen
const adContainer = document.createElement('div')
adContainer.style.cssText = `
position: relative;
width: 100vw;
height: 100vh;
background: white;
overflow: hidden;
`
// Schließen-Button erstellen
const closeButton = document.createElement('button')
closeButton.innerHTML = '✕'
closeButton.style.cssText = `
position: absolute;
top: 10px;
right: 10px;
width: 40px;
height: 40px;
border: none;
background: rgba(0, 0, 0, 0.7);
color: white;
font-size: 20px;
border-radius: 50%;
cursor: pointer;
z-index: 1000000;
`
closeButton.onclick = () => {
document.body.removeChild(overlay)
console.log('🚪 Interstitial-Anzeige geschlossen')
}
// Anzeigenformat bestimmen und Inhalt erstellen
let adContent = ''
// Format 1: Iframe-Anzeige
if (adData.html && adData.html.includes('iframe.php')) {
`
<iframe
src="${adData.html}"
width="100%"
height="100%"
frameborder="0"
allowfullscreen
sandbox="allow-scripts allow-forms allow-popups"
style="width: 100vw; height: 100vh; border: none;"
></iframe>
`
console.log('🖼️ Iframe-Anzeige erstellt')
} if (adData.html && adData.html.includes('iframe.php')) {
`
<iframe
src="${adData.html}"
width="100%"
height="100%"
frameborder="0"
allowfullscreen
sandbox="allow-scripts allow-forms allow-popups"
style="width: 100vw; height: 100vh; border: none;"
></iframe>
`
console.log('🖼️ Iframe-Anzeige erstellt')
}
// Format 2: Video-Anzeige
else if (adData.video) {
const hasClickUrl = adData.url && adData.url.trim() !== ''
if (hasClickUrl) {
// Video mit Klick-Weiterleitung
`
<div style="position: relative; width: 100vw; height: 100vh; cursor: pointer;"
onclick="window.open('${adData.url}', '_blank')">
<video
width="100%"
height="100%"
autoplay
muted
loop
style="object-fit: cover; width: 100vw; height: 100vh;"
>
<source src="${adData.video}" type="video/mp4">
</video>
<div style="
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
">
Klicken Sie, um den Werbetreibenden zu besuchen
</div>
</div>
`
console.log('🎬 Klickbares Video-Banner erstellt')
} else {
// Normales Video
`
<video
width="100%"
height="100%"
autoplay
muted
controls
style="object-fit: cover; width: 100vw; height: 100vh;"
>
<source src="${adData.video}" type="video/mp4">
</video>
`
console.log('🎬 Videoanzeige erstellt')
}
}
// Format 3: Klick-Weiterleitungs-Anzeige
else if (adData.url) {
`
<div style="
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
background: linear-gradient(45deg, #0072ba, #28a745);
padding: 20px;
">
<h2 style="color: white; margin-bottom: 20px; font-size: 48px;">
🎯 Interstitial-Anzeige
</h2>
<p style="color: white; margin-bottom: 30px; font-size: 24px;">
Klicken Sie, um den Werbetreibenden zu besuchen
</p>
<a href="${adData.url}"
target="_blank"
style="
padding: 15px 30px;
background: white;
color: #0072ba;
text-decoration: none;
border-radius: 25px;
font-weight: bold;
font-size: 18px;
">
Jetzt besuchen
</a>
</div>
`
console.log('🔗 Klick-Weiterleitungs-Anzeige erstellt')
}
// Format 4: Native Anzeigen
else if (adData.ad_items && adData.ad_items.length > 0) {
const adItemsHtml = adData.ad_items.map((item: any) => `
<div style="
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
cursor: pointer;
" onclick="window.open('${item.url}', '_blank')">
<div style="height: 200px; overflow: hidden;">
<img src="${item.optimum_image || item.image}"
style="width: 100%; height: 100%; object-fit: cover;"
alt="${item.title}">
</div>
<div style="padding: 15px;">
<h3 style="margin: 0 0 8px 0; font-size: 18px;">${item.title}</h3>
${item.description ? `<p style="font-size: 14px; color: #666;">${item.description}</p>` : ''}
<div style="font-size: 12px; color: #999;">${item.brand || 'Gesponsert'}</div>
</div>
</div>
`).join('')
`
<div style="
width: 100vw;
height: 100vh;
background: #f5f5f5;
overflow-y: auto;
padding: 20px;
">
<h2 style="text-align: center; margin-bottom: 20px;">Gesponserte Inhalte</h2>
<div style="
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
">
${adItemsHtml}
</div>
</div>
`
console.log('🎯 Native-Anzeigenraster erstellt')
}
// Inhalt zum Container hinzufügen
adContainer.innerHTML = adContent
adContainer.appendChild(closeButton)
overlay.appendChild(adContainer)
document.body.appendChild(overlay)
// Impression verfolgen
if (adData.impression) {
fetch(adData.impression, { method: 'GET', mode: 'no-cors' })
.then(() => console.log('📊 Impression verfolgt'))
.catch(e => console.log('⚠️ Impression-Tracking fehlgeschlagen:', e))
}
} catch (error) {
console.error('❌ Fehler bei der Anzeige der Werbung:', error)
}
}return (
<div>
<h1>Meine Seite</h1>
<button onClick={triggerFPIAd}>
FPI-Anzeige laden
</button>
</div>
)