ingestion

Send data in

The tracker snippet covers pageviews and events automatically. These endpoints let your backend push payments, tie a session to a known user, and shorten links.

POST/api/v1/payment
Record a payment from any provider (Paddle, Polar, WooCommerce, custom). Attribute it to a visit with ref or email.
ParamTypeDescription
amountreqnumberAmount (negative or refund:true for a refund).
currencyreqstringISO currency, e.g. USD.
transaction_idreqstringYour id, used for dedup.
refstringwindow.datalenk.ref captured on your site.
emailstringCustomer email, hashed server-side for attribution.
refundbooleanMark this as a refund.
curl -X POST https://datalenk.com/api/v1/payment \
  -H "Authorization: Bearer dlk_…" -H "Content-Type: application/json" \
  -d '{ "amount": 29.99, "currency": "USD", "transaction_id": "txn_98hj", "ref": "…" }'
POST/api/v1/identify
Link a session to a known email so future payments attribute correctly.
POST/api/v1/links
Upsert tracked-link metadata (this is how Lenkli pushes its links in). Clicks and revenue join by slug. It does not create links: Lenkli does that.
POST/api/event
The endpoint the dl.js snippet posts to. You normally never call this by hand; the tracker does.

The server beacon (AI crawlers)

AI crawlers do not run JavaScript, so no client-side script can ever see them, ours included. To get AI visibility (who crawls you, who cites you, and what that turns into), send one call per request from your middleware or edge function. We identify the crawler, and we verify it against published IP ranges and reverse DNS, so a spoofed user-agent cannot pollute your numbers.

POST/api/server
Server-side beacon: report a request (user-agent, path, IP) so AI crawlers show up in your dashboard.
middleware.ts (Next.js)
export function middleware(req: Request) {
  // fire and forget, never block the response
  fetch("https://datalenk.com/api/server", {
    method: "POST",
    headers: { "Authorization": "Bearer dlk_…", "Content-Type": "application/json" },
    body: JSON.stringify({
      site_id: 42,
      ua: req.headers.get("user-agent") ?? "",
      ip: req.headers.get("cf-connecting-ip") ?? req.headers.get("x-forwarded-for") ?? "",
      path: new URL(req.url).pathname,
    }),
  }).catch(() => {});
  return;
}
Auth on this page is different. The ingestion endpoints below (/payment, /identify, /links) authenticate with your workspace token (Dashboard, API, starts with dlk_), not with a scoped API key. The scoped keys (dlk_live_…) are for the read and export endpoints.

The tracker

Every site needs the snippet once, on all pages. Creating a site returns it — including your site's data-key.

index.html
<script defer data-site="42" data-key="dk_..." src="https://in.datalenk.com/dl.js"></script>

By default the tracker is cookieless: it writes nothing to visitors' devices (no cookies, no localStorage) — no consent banner needed. Optional attributes:

  • data-persist — enables the Persistent layer (returning visitors, cohorts, multi-day attribution) by storing a first-party pseudonymous id (localStorage + datalenk_ref cookie). Enable it from Settings → Tracking depth first: it walks you through the privacy-policy/consent implications.
  • data-no-cookie — with data-persist, keeps the id in localStorage only (no cookie).
  • data-key — your site's public ingestion key (anti-spoofing). Shown in Settings → Install.