ADR 0010 — Conversion Attribution: Click Id, Customers, trackLead / trackSale
Status: Accepted (★ new; the open equivalent of @dub/analytics + Dub’s track API)
Context
Section titled “Context”“Which link brought this signup / this sale?” is the reason teams pay for Dub. It needs a click id that survives the redirect, a way to bind it to the host’s customer, and events in the same sink as clicks.
Decision
Section titled “Decision”- When
link.trackConversionsis on (or globally viaconversions: { enabled: true }), the redirect appendsxl_id={clickId}(param name configurable) to the destination and stores aClickRef { clickId, tenant, linkId, at }(pruned afterattributionWindow, default 90 d). - The
@xtandard/links/clientsubpath (zero-dep, browser) reads the param, persists it in a first-party cookie (xl_id, 90 d) and strips it from the address bar;getClickId()returns it so the host forwards it with its signup request. - Server-side:
core.trackLead({ clickId, customerId, name, metadata })binds the customer to the click (Customer { id, tenant, clickId, linkId, firstSeenAt }) and ingests aleadevent;core.trackSale({ customerId, amount, currency, invoiceId?, name })resolves the customer’s click and ingests asaleevent (idempotent oninvoiceId). Unknown click ids →nullresult, not an error (attribution is best-effort). - HTTP:
POST /api/track/leadand/api/track/saleon the panel, authorized by theconversion:trackaction (use a dedicated API-key principal viaauth/basicordelegated). - Metrics:
leads,sales,saleAmount(minor units, per currency in breakdowns) appear next toclicksin every analytics query.
Consequences
Section titled “Consequences”- Attribution model is last-click per customer (first lead wins the binding); documented.
- No third-party cookies; the cookie is set on the host’s own domain by the host’s page.