Wie man mit AdBlock Dynamic Domains API arbeitet
AdBlock-Tools werden immer ausgefeilter und stellen Publisher, die ihre Einnahmen aus Online-Werbung maximieren wollen, vor große Herausforderungen. Um diese Herausforderungen zu entschärfen, ermöglicht diese API Publishern die dynamische Anpassung ihrer Skripte auf der Grundlage aktiver Domains, wodurch das Risiko, dass Inhalte von AdBlock-Software blockiert werden, erheblich reduziert wird.
Durch die Sicherstellung der Anzeigenauslieferung über regelmäßig rotierende Domains können Publisher:
- Aufrechterhaltung von Einnahmequellen: Verhindern Sie Unterbrechungen durch blockierte Werbung.
- Verbessern Sie das Nutzererlebnis: Liefern Sie Anzeigeninhalte nahtlos aus, ohne die AdBlock-Erkennung auszulösen.
- Automatisierte Domain-Verwaltung: Keine manuellen Aktualisierungen mehr dank eines automatisierten 7-tägigen Domain-Lebenszyklus.
Neue Domains werden alle 3 Tage generiert und sind über die API verfügbar. Die Domains haben einen Lebenszyklus von 6 Tagen.
- 3 Tage aktiv
- 3 Tage veraltet
Sobald der Lebenszyklus abläuft, wird die Domäne deaktiviert. Aus Leistungsgründen wird empfohlen, die Domäne 24 Stunden lang zwischenzuspeichern, bevor eine neue Domäne über die API angefordert wird.
Diese API ist nur für die Bereiche Popunders inline-script und In-Stream Video verfügbar.
Anforderungen
Um diese API zu nutzen, müssen die Verlage :
- Stellen Sie eine GET-Anfrage an den Endpunkt: https://ads.exoclick.com/adblock-domains.php
- In der Antwort erhalten Sie eine neue Domain für die Anzeigenschaltung
- Sie müssen dann den Syndikationsendpunkt, der in Ihrem Anzeigenzonen-Tag verwendet wird, in den neuen Endpunkt ändern, der in der API-Antwort angegeben ist.
Schritte zur Umsetzung
Schritt 1. Abrufen der aktiven Domäne
Um den aktiven Bereich dynamisch abzurufen, müssen Sie einen API-Aufruf von Server zu Server tätigen. Dies ist wichtig, da API-Aufrufe blockiert werden können, wenn sie von der Client-Seite aus aufgerufen werden.
Server-zu-Server-Anfrage (PHP-Beispiel)
<?php
function fetchAdblockDomain()
{
$endpoint = 'https://ads.exoclick.com/adblock-domains.php'; // your ads domain
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('Error cURL: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
return $response;
} else {
throw new Exception("HTTP Error: {$httpCode} - Response: {$response}");
}
}
try {
echo fetchAdblockDomain();
} catch (Exception $e) {
echo json_encode(['message' => $e->getMessage()]);
}
?>
Erwartete Antwort von der API
{
"success": true,
"message": "Domain found",
"domain": "newsub.newdomain.com" // example
}
Schritt 2. Aktualisieren Sie Ihr Skript
- Holen Sie sich das Skript, das im HTML-Tag Zone bereitgestellt wird
- Verwenden Sie die vom Endpunkt zurückgegebene Domäne
- Für In-Stream Video Zonen ändern Sie den VAST Tag:
- Before :
https://s.magsrv.com/v1/vast.php?idzone={zoneId}
- After :
https://newsub.newdomain.com/v1/vast.php?idzone={zoneId}
- Before :
- Für Popunders-Zonen ändern Sie den syndication_host im Inline-Skript:
- Vor : s.pemsrv.com
- After : newsub.newdomain.com
Erkennung von AdBlock
Mit dem folgenden Codeschnipsel können Sie feststellen, ob der Client AdBlock aktiviert hat. Dadurch können Sie die entsprechende Domäne für die Anfrage auswählen und block=1 anhängen, um die AdBlock-Tracking-Statistiken zu verbessern. Siehe das Beispiel unten:
// This script will be blocked by Adblock in case of the client is using it, due to the presence of the "exoclick" and "ads" keywords.
// After loading this script, a JS snipppet will attempt to read a specific variable.
// If the variable is undefined or inaccessible, we can determine that the script as been blocked.
<script src="https://www.exoclick.com/ads.js" type="text/javascript"></script>
<script>
// Initialize the insDomain variable with a default value
let insDomain = 's.magsrv.com'; // Generic host for the network
let adb = ""; // This variable may contain "&block=1" which helps track Adblock Statistics
// Fetch adblock domains using a GET request to the PHP file
async function fetchAdblockDomains() {
try {
// Perform a GET request to fetchAdblockDomain.php (Step 3.A).
// This is a server-to-server request to retreive the Adblock Domain.
const response = await fetch('fetchAdblockDomain.php', {
method: 'GET', // Specify the GET method
});
// Check if the response is successful (status 200)
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// Parse the response as JSON
const data = await response.json();
console.log('Response data:', data); // Log the response data for debugging
// Call the function to process the domains
displayDomains(data);
} catch (error) {
// Log any errors that occur during the fetch
console.error('Error fetching domains:', error);
}
}
// Process and display the domains, updating insDomain if success is true
function displayDomains(domains) {
console.log('Success status:', domains["success"]); // Log the success status
console.log('Fetched domain:', domains["domain"]); // Log the fetched domain
// Update the insDomain variable if the success flag is true
if (domains["success"] && typeof bait_b3j4hu231 === 'undefined') {
adb = '&block=1';
insDomain = domains["domain"];
console.log('Updated insDomain:', insDomain); // Log the updated value of insDomain
}
// Now you should initialize Fluid Player using the vast tag:
// "https://" + insDomain + "v1/vast.php?idzone=ZONEID" + adb
}
// Automatically call fetchAdblockDomains when the page loads
window.onload = fetchAdblockDomains;
</script>
Beispiel für Integration
Schritt 1 - Server-seitige PHP-Datei (fetchAdblockDomain.php)
Erstellen Sie eine Datei mit dem Namen "fetchAdblockDomain.php" auf Ihrem Server:
<?php
function fetchAdblockDomain()
{
$endpoint = 'https://ads.exoclick.com/adblock-domains.php';
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('Error cURL: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
return $response;
} else {
throw new Exception("HTTP Error: ({$httpCode}) Response: {$response}");
}
}
try {
echo fetchAdblockDomain();
} catch (Exception $e) {
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
}
?>
Dieses PHP-Skript holt eine neue Domain für die Anzeigenschaltung ab.
Schritt 2 - JavaScript-Logik zum Abrufen und Anwenden
Im Abschnitt <script>
:
<script src="https://www.exoclick.com/ads.js" type="text/javascript"></script>
<script>
let insDomain = 's.magsrv.com'; // default
let adb = '';
let rdm = '';
const ZONE_ID_PRE_ROLL = 'XXXXXXX';
async function fetchAndApplyAdblockDomains() {
try {
const response = await fetch('fetchAdblockDomain.php');
const data = await response.json();
console.log('Response:', data);
if (data.success && typeof bait_b3j4hu231 === 'undefined') {
// AdBlock detected
adb = '&block=1';
insDomain = data.domain;
console.log('AdBlock detected: using API domain', insDomain);
} else if (data.success) {
// No AdBlock
insDomain = 's.magsrv.com';
console.log('No AdBlock: using default domain');
} else {
console.warn('Fallback: Using default domain due to error or no success');
}
} catch (err) {
console.error('Error fetching domain:', err);
// Fallback to default domain
}
// Initialize Fluid Player
fluidPlayer('example-player', {
layoutControls: {
primaryColor: "#28B8ED",
controlForwardBackward: {
show: true,
doubleTapMobile: false
},
timelinePreview: {
file: 'thumbnails.vtt',
type: 'VTT'
}
},
vastOptions: {
adList: [
{
roll: "preRoll",
vastTag: `https://${insDomain}/v1/vast.php?${rdm}idzone=${ZONE_ID_PRE_ROLL}${adb}`,
timer: 5
}
]
}
});
}
window.onload = fetchAndApplyAdblockDomains;
</script>
Fehlersuche
Gemeinsame Probleme
Zum Beispiel wurde keine Domäne zurückgegeben:
{
"success": false,
"message": "Domain not found"
}
Wenn der Erfolg falsch ist, wenden Sie sich an den Support.
Protokollieren Sie während der Fehlersuche immer die Antwort des Endpunkts, um mögliche Probleme zu erkennen.
For further assistance, contact the support team here.