Track Referral Click
Public endpoint. Increments the click counter on a ReferralLink. Silent on missing/inactive codes — the request never fails.
POST /api/v1/referral/click/:code — 🌐 Public · Rate limit: 60 req / minute · Kill-switched
Increments the clicks counter on the ReferralLink row matching code. Public — no auth required (clicks come from landing pages where the visitor isn't signed in yet). Silent on missing/inactive codes: if the code doesn't exist, the database update fails internally, the failure is logged at warn level, and the response is still 200 OK.
Always returns tracked: true. Whether the code matched or not, the response shape is identical. This is intentional — landing pages call this from JavaScript and shouldn't block on tracking failures. The server logs the failure for observability.
Click counter is best-effort, not auditable. The clicks increment is unguarded — no duplicate suppression, no IP tracking, no bot filtering. For the actual referral attribution chain, the platform records signups (in recordSignup) and conversions (in commission-paid flows) which are tied to authenticated user creation, not click events.
Request
Path parameters
| Param | Type | Notes |
|---|---|---|
code | string | The referral code (no UUID pipe — raw string) |
No body, no headers required.
Response
200 OK — ApiResponseOf<TrackClickResponseDto>
{
"success": true,
"data": {
"tracked": true
}
}| Field | Type | Notes |
|---|---|---|
tracked | boolean | Always true on 200 — even if the code doesn't exist (silent failure path) |
Errors
| HTTP | code / i18nKey | Reason |
|---|---|---|
429 | (throttle) | Rate limit exceeded (60 req/min) |
503 | features.referral_disabled | Admin kill switch REFERRAL is active |
The endpoint does not return 4xx for missing codes — see callout.
Side effects
resolveLinkByCode(code)(alias-aware): triesreferralLink.findUnique({ where: { code } })first, then falls back toreferralLinkAlias.findUnique({ where: { code }, include: { referralLink: true } }). Returnsnullif neither matches.- No link (neither live code nor alias) → log warn
[referral] Click tracking: no link found for code <code>and return without writing anything. Response is still200 OK { tracked: true }. - Link found →
prisma.referralLink.update({ where: { id: link.id }, data: { clicks: { increment: 1 } } }). The increment targets theReferralLink.idreturned by the resolver, so a click onbio.re/ref/<oldcode>(alias) and a click onbio.re/ref/<newcode>(live) both increment the same row'sclickscounter — no double-counting, and aliases don't carry counters of their own. .catch()-d to a warn log on failure (e.g. DB transient issue). Failure does NOT propagate.- Return
{ tracked: true }.
Old shared URLs keep working. When a user renames a vanity username, the old referral code is preserved as a ReferralLinkAlias (see Change Username · Referral code side-effect). Click tracking transparently follows the alias to the same ReferralLink, so previously printed/shared bio.re/ref/<oldcode> links continue to credit the original referrer.
Code samples
curl -X POST https://api.bio.re/api/v1/referral/click/alice123async function trackReferralClick(code: string): Promise<void> {
// Fire-and-forget — landing page navigation should never block on this
await fetch(`https://api.bio.re/api/v1/referral/click/${encodeURIComponent(code)}`, {
method: 'POST',
}).catch(() => { /* swallow — analytics is non-critical */ });
}<!-- /ref/[code]/page.tsx (Next.js) -->
<script>
// Extract code from URL: /ref/alice123 → 'alice123'
const code = window.location.pathname.split('/').filter(Boolean).pop();
if (code) {
fetch(`/api/v1/referral/click/${code}`, { method: 'POST' }).catch(() => {});
}
</script>Try it
curl -X POST "https://loading/api/v1/referral/click/string"{
"success": true,
"data": {
"tracked": true
}
}Source
| Source | Path | Lines |
|---|---|---|
| Controller | apps/api-core/src/modules/referral/referral.controller.ts | 49–56 (trackClick) |
| DTO (response) | apps/api-core/src/modules/referral/dto/referral-response.dto.ts | 311–314 (TrackClickResponseDto) |
| Service (track) | apps/api-core/src/modules/referral/referral.service.ts | 63–72 (trackClick) |
| Service (alias resolver) | apps/api-core/src/modules/referral/referral.service.ts | 23–32 (resolveLinkByCode) |
| Prisma models | packages/prisma/prisma/schema.prisma | ReferralLink 2103–2119 (clicks counter, line 2107), ReferralLinkAlias 2121–2130 (resolver fallback path) |
| Live response | MISSING — to be captured by Lead before publish | — |
Get Referral Link
Get-or-create the calling user's personal referral link. First call generates a code from their username (or random UUID slice on collision); subsequent calls return the existing one.
Get Referral Dashboard
Authenticated. Returns the user's referral link snapshot (clicks, signups, conversions, totalEarnings) plus their last 50 active rewards (clawed-back rewards excluded).