Skip to content

A tour of the features

Rules are evaluated in order; the first rule whose conditions all match wins. A rule sends visitors to one URL or splits them across weighted variants — deterministically, so a visitor keeps seeing the same variant.

await core.createLink({
slug: "app",
url: "https://acme.com/download",
ios: "https://apps.apple.com/app/id123456789",
android: "https://play.google.com/store/apps/details?id=com.acme",
rules: [
{
when: [{ field: "country", op: "in", values: ["DE", "AT", "CH"] }],
url: "https://acme.de/download",
},
{
name: "Landing page test",
when: [{ field: "device", op: "in", values: ["desktop"] }],
variants: [
{ id: "a", url: "https://acme.com/download?v=a", weight: 50 },
{ id: "b", url: "https://acme.com/download?v=b", weight: 50 },
],
},
],
});

Conditions: device, os, browser, country, continent, language, referrer, qr, query parameters and time windows. See Rules and ADR 0011.

Every redirect becomes a click event — captured after the response, batched, and written to an analytics sink:

  • Bots and link previews are detected (isBot, isPreviewBot) and flagged, never counted as clicks (or dropped with bots: "drop").
  • Device, OS and browser come from a built-in user-agent parser; country, region, city from edge headers (Cloudflare, Vercel, CloudFront, Fastly) or your own GeoResolver (e.g. MaxMind).
  • Privacy first: IPs are dropped by default (privacy.ip: "truncate" | "hash" | "full" to opt in); unique visitors are a daily-salted hash; respectDoNotTrack honours DNT / GPC.
const stats = await core.queryAnalytics({
tenant: "default",
from: "2026-11-01T00:00:00Z",
to: "2026-12-01T00:00:00Z",
interval: "day",
groupBy: "country",
});
// → { totals: { clicks, botClicks, leads, sales, saleAmount }, timeseries: [...], breakdown: [...] }

The default sink stores hourly and daily rollups in the same storage as your links. When you outgrow it, swap the sink and keep everything else:

import { createClickHouseAnalytics } from "@xtandard/links/analytics/clickhouse";
const core = createLinksCore({
storage,
analytics: createClickHouseAnalytics({ url: process.env.CLICKHOUSE_URL!, createTable: true }),
});

Tinybird (analytics/tinybird) and Cloudflare Workers Analytics Engine (analytics/analytics-engine) work the same way; all sinks pass one conformance suite. See Analytics and ADR 0006.

“Which link brought this signup?” Turn on trackConversions and the redirect appends a click id (?xl_id=clk_…) to the destination. Capture it on your site and report conversions server-side:

// In the browser, on your landing pages:
import { captureClickId, getClickId } from "@xtandard/links/client";
captureClickId(); // stores xl_id in a first-party cookie, cleans the URL
// On your server, when the visitor signs up / pays:
await core.trackLead({ clickId, customerId: user.id, name: "Sign up" });
await core.trackSale({ customerId: user.id, amount: 4900, currency: "USD", invoiceId: "inv_123" });

Leads and sales show up next to clicks in every analytics query. See Conversions.

Register your apps on a domain and the redirect handler serves the association files the OS needs for universal links / app links:

await core.createDomain({
hostname: "go.acme.com",
apps: {
ios: { appIds: ["ABCDE12345.com.acme.app"] },
android: [{ packageName: "com.acme.app", sha256CertFingerprints: ["AB:CD:…"] }],
},
});
// GET https://go.acme.com/.well-known/apple-app-site-association
// GET https://go.acme.com/.well-known/assetlinks.json

Visitors without the app are routed to link.ios / link.android (the store listing, with the Play install referrer carrying the click id). With deepLink: { path: "/product/42", deferred: true } the app can claim the original destination on first open — POST /_links/deferred/claim — exact by click id or by a privacy-preserving fingerprint. See Deep links.

Show each of your customers the clicks on their links, inside your product. Mint a short-lived, tenant-scoped viewer token server-side and render the widget:

import { createViewerToken } from "@xtandard/links";
const token = await createViewerToken(process.env.LINKS_VIEWER_SECRET!, { tenant: org.id });
import { LinkAnalytics } from "@xtandard/links/react";
import "@xtandard/links/react/styles.css";
<LinkAnalytics apiBaseUrl="/links" token={token} />;

Tokens are stateless HMAC grants, force-scoped to one tenant (optionally to specific links) and to the actions you allow. See Analytics widget and ADR 0009.