How to work with AdBlock Dynamic Domains API
AdBlock tools are increasingly sophisticated, posing significant challenges for publishers seeking to maximize revenue from online advertising. To help mitigate these challenges, this API allows publishers to dynamically adjust their scripts based on active domains, significantly reducing the risk of content being blocked by AdBlock software.
By ensuring ad delivery through regularly rotated domains, publishers can:
- Maintain Revenue Streams: Prevent interruptions caused by blocked ads.
- Enhance User Experience: Deliver ad content seamlessly without triggering AdBlock detection.
- Automate Domain Management: Eliminate manual updates with an automated 7-day domain lifecycle.
New domains are generated every 3 days and are available through the API. The domains will have a 6-day lifecycle.
- 3 days active
- 3 days deprecated
Once the lifecycle expires, the domain will be deactivated. For performance reasons, it is recommended to cache the domain for 24 hours before requesting a new domain from the API.
This API is only available for Popunders inline-script and In-Stream Video zones.
Anforderungen
To use this API, publishers need to :
- Make a GET request to the endpoint: https://ads.exoclick.com/adblock-domains.php
- You will receive a new ad-serving domain in the response
- You must then change the syndication endpoint used on your ad zone tag to the new one provided in the API response.
Steps to Implement
Step 1. Fetch the Active Domain
To retrieve the active Domain dynamically, you must make an API call server-to-server. This is crucial because API calls can be blocked if called from the client side.
Server-to-Server Request (PHP example)
<?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()]);
}
?>
Expected response from the API
{
"success": true,
"message": "Domain found",
"domain": "newsub.newdomain.com" // example
}
Step 2. Update Your Script
- Get the script provided on the Zone HTML tag
- Use the domain returned from the endpoint
- For In-Stream Video zones change the VAST Tag:
- Before :
https://s.magsrv.com/v1/vast.php?idzone={zoneId}
- After :
https://newsub.newdomain.com/v1/vast.php?idzone={zoneId}
- Before :
- For Popunders zones change the syndication_host on the inline script:
- Before : s.pemsrv.com
- After : newsub.newdomain.com
Detecting AdBlock
The following code snippet allows you to detect whether the client has AdBlock enabled. This enables you to select the appropriate domain for the request and append block=1 to improve AdBlock tracking statistics. See the example below:
// 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>
Integration Example
Step 1 – Server-side PHP File (fetchAdblockDomain.php)
Create a file named fetchAdblockDomain.php
on your 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()
]);
}
?>
This PHP script fetches a new domain for ad delivery.
Step 2 – JavaScript Logic to Fetch and Apply
In the <script>
section:
<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
Common Issues
No domain returned, for example:
{
"success": false,
"message": "Domain not found"
}
If success is false, contact support.
Always log the endpoint’s response during debugging to identify potential issues.
For further assistance, contact the support team here.