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
prisma.referralLink.update({ where: { code }, data: { clicks: { increment: 1 } } })..catch()-d to a warn log on failure (e.g. unknown code, DB transient issue). Failure does NOT propagate.- Return
{ tracked: true }.
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 | apps/api-core/src/modules/referral/referral.service.ts | 49–53 (trackClick) |
| Prisma model | packages/prisma/prisma/schema.prisma | ReferralLink.clicks (counter) |
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).