Kod örnekleri
Aşağıdaki kodu olduğu gibi kopyalayabilirsiniz; hiçbir paket kurmanız gerekmez.
Her sipariş için üç şey yapılır: sitedeki _adall çerezinden reklam tıklamasını okumak, e-postayı SHA-256 ile özetlemek ve isteği gizli değerinizle imzalamak.
Node.js (18 ve üstü)
import crypto from "node:crypto";
const sha256 = (text) => crypto.createHash("sha256").update(text).digest("hex");
// adall.js'in yazdığı _adall çerezi: son reklam tıklaması ve ilk ziyaret.
function touchFromCookie(raw) {
try {
const v = JSON.parse(Buffer.from(decodeURIComponent(raw ?? ""), "base64").toString());
return { click_ids: v.last?.click_ids ?? {}, utm: v.last?.utm ?? {}, session: { landing_url: v.first?.landing_url, first_touch_at: v.first?.at } };
} catch { return {}; }
}
export async function sendOrder({ reference, amountMinor, currency, email, country, cookie, consentGranted, source, proofId }) {
const body = JSON.stringify({ schema_version: 1, events: [{
event_id: `order-${reference}`, type: "order", occurred_at: new Date().toISOString(), reference: String(reference),
value: { amount_minor: amountMinor, currency }, country,
customer: email ? { email_sha256: sha256(email.trim().toLowerCase()) } : {},
consent: { ad_user_data: consentGranted ? "granted" : "denied", source, proof_id: proofId },
...touchFromCookie(cookie),
}] });
const ts = String(Math.floor(Date.now() / 1000));
const sig = crypto.createHmac("sha256", process.env.ADALL_SECRET).update(`${ts}.${body}`).digest("hex");
const res = await fetch("https://live.adall.io/api/v1/events", { method: "POST", body, headers: {
"Content-Type": "application/json", "X-Adall-Key": process.env.ADALL_KEY, "X-Adall-Timestamp": ts, "X-Adall-Signature": `sha256=${sig}`,
} });
return res.ok;
}
// Örnek: await sendOrder({ reference: 1001, amountMinor: 45000, currency: "TRY", email, country: "TR",
// cookie: req.cookies._adall, consentGranted: true, source: "veribenim", proofId });PHP / Laravel
function adallTouch(?string $raw): array
{
$v = json_decode((string) base64_decode(rawurldecode((string) $raw), true), true);
if (! is_array($v)) return [];
return ['click_ids' => $v['last']['click_ids'] ?? [], 'utm' => $v['last']['utm'] ?? [],
'session' => array_filter(['landing_url' => $v['first']['landing_url'] ?? null, 'first_touch_at' => $v['first']['at'] ?? null])];
}
function adallSendOrder(string $reference, int $amountMinor, string $currency, ?string $email, ?string $country, bool $consentGranted, string $source, ?string $proofId): bool
{
$body = json_encode(['schema_version' => 1, 'events' => [array_filter([
'event_id' => 'order-'.$reference, 'type' => 'order', 'occurred_at' => now()->toAtomString(), 'reference' => $reference,
'value' => ['amount_minor' => $amountMinor, 'currency' => $currency], 'country' => $country,
'customer' => $email ? ['email_sha256' => hash('sha256', mb_strtolower(trim($email)))] : null,
'consent' => array_filter(['ad_user_data' => $consentGranted ? 'granted' : 'denied', 'source' => $source, 'proof_id' => $proofId]),
]) + adallTouch(request()->cookie('_adall'))]]);
$ts = (string) time();
$sig = hash_hmac('sha256', $ts.'.'.$body, config('services.adall.secret'));
return Http::withHeaders(['X-Adall-Key' => config('services.adall.key'), 'X-Adall-Timestamp' => $ts, 'X-Adall-Signature' => 'sha256='.$sig])
->withBody($body, 'application/json')->post('https://live.adall.io/api/v1/events')->successful();
}countrysiparişin gönderim ülkesidir (iki harf); ülke tutma testleri gerçek satışı bununla ölçer.- Zaman damgası 5 dakikadan eskiyse istek reddedilir; sunucu saatinizin doğru olduğundan emin olun.
- İstek başarısız olursa siparişinizi durdurmayın; daha sonra aynı
event_idile yeniden gönderebilirsiniz, bir kez sayılır.