AdBlock Dynamic Domains APIを使用する方法
AdBlock ツールはますます洗練されており、オンライン広告からの収益を最大化しようとするパブリッシャーにとって大きな課題となっています。これらの課題を軽減するために、このAPIを使用することで、パブリッシャーはアクティブなドメインに基づいてスクリプトを動的に調整することができ、コンテンツがAdBlockソフトウェアによってブロックされるリスクを大幅に軽減することができます。
定期的にローテーションされたドメインを通じて広告配信を確保することで、パブリッシャーは次のことが可能になる:
- 収入の流れを維持する: ブロックされた広告によって引き起こされる中断を防ぐ。
- ユーザーエクスペリエンスの向上: AdBlock検出をトリガーすることなく、広告コンテンツをシームレスに配信します。
- ドメイン管理の自動化:自動化された7日間のドメインライフサイクルで手動更新を排除します。
新しいドメインは3日ごとに生成され、APIを通じて利用できる。ドメインのライフサイクルは6日間です。
- 3日間アクティブ
- 3日非推奨
ライフサイクルが終了すると、ドメインは無効化されます。パフォーマンス上の理由から、APIから新しいドメインをリクエストする前に、ドメインを24時間キャッシュすることをお勧めします。
このAPIはPopunders inline-scriptとIn-Stream Videoゾーンでのみ利用可能です。
必要条件
このAPIを使用するには、パブリッシャーは.NET Frameworkが必要です:
- エンドポイントにGETリクエストを行う: https://ads.exoclick.com/adblock-domains.php
- レスポンスに新しい広告配信ドメインが表示されます。
- その後、広告ゾーンタグで使用されているシンジケーションエンドポイントを、APIレスポンスで提供された新しいものに変更する必要があります。
実施までのステップ
ステップ1.アクティブドメインを取得する
アクティブドメインを動的に取得するには、サーバー間でAPIコールを行う必要がある。クライアント側からAPIコールを呼び出すとブロックされる可能性があるため、これは非常に重要です。
サーバー間リクエスト(PHPの例)
<?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()]);
}
?>
APIから期待されるレスポンス
{
"success": true,
"message": "Domain found",
"domain": "newsub.newdomain.com" // example
}
ステップ2.スクリプトを更新する
- ゾーンHTMLタグで提供されるスクリプトを取得する
- エンドポイントから返された**ドメインを使用する。
- インストリームビデオ*ゾーンの場合は、VASTタグ*を変更してください:
- Popunders ゾーンでは、インラインスクリプトの syndication_host を変更してください:
- 前 : s.pemsrv.com
- その後 : newsub.newdomain.com
アドブロックの検出
以下のコード・スニペットにより、クライアントがAdBlockを有効にしているかどうかを検出できます。これにより、リクエストに適切なドメインを選択し、block=1を追加することで、AdBlockトラッキング統計を改善することができます。以下の例を参照してください:
// 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>
統合の例
ステップ1 - サーバー側のPHPファイル (fetchAdblockDomain.php)
サーバーにfetchAdblockDomain.phpというファイルを作成します:
<?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()
]);
}
?>
このPHPスクリプトは、広告配信用の新しいドメインを取得します。
ステップ2 - JavaScriptロジックによるフェッチと適用
<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>
トラブルシューティング
よくある問題
例えば、ドメインが返されない:
{
"success": false,
"message": "Domain not found"
}
成功が偽の場合は、サポートに連絡してください。
潜在的な問題を特定するために、デバッグ中は常にエンドポイントのレスポンスをログに記録する。
詳しくは、サポートチームこちらまでお問い合わせください。