Docs

Code examples

Code examples

Copy the code below as it is; there is no package to install.

Each order takes three steps: read the ad click from the site's _adall cookie, hash the e-mail with SHA-256, and sign the request with your secret.

Node.js (18 or later)

import crypto from "node:crypto";

const sha256 = (text) => crypto.createHash("sha256").update(text).digest("hex");

// The _adall cookie written by adall.js: the last ad click and the first visit.
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;
}

// Example: 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();
}
  • country is the order's shipping country (two letters); country holdout tests measure real sales with it.
  • A timestamp older than 5 minutes is refused; make sure your server's clock is right.
  • If the request fails, do not stop the order; send it again later with the same event_id and it is counted once.