Playground features

Affiliate and referral tracking

Referral tracking, affiliate signup, and a payout-ready ledger

Gives each promoter their own link, counts the signups it brings in and works out what they are owed. Taken from a referral system live in a real product.

Three colored signposts each with a winding path leading to the same door, and beside each signpost a stack of coins at a different height

A feature of the Playground

This is a feature of the Vibe Coder Playground. It runs inside the Playground, with its audit record and its caveats beside it.

Download the Playground See pricing

The mistake it removes

Referral attribution is money, so the failure modes are money-shaped. The three that bite: SELF-REFERRAL (an affiliate buys through their own link), an attribution window with no upper bound (a cookie set once earns commission forever), and a commission recorded before the payment settles: a refunded order that already paid out. The first two are refused in recordConversion() and named in the code. The third is handled by order of calls plus a reversal: record only after the charge settles, keep the row pending through your refund window, and call reverse() from your refund webhook, which moves the commission to reversed and writes an audit row. Each of these is invisible until an invoice is wrong.

What the audit found

Named rather than summarized. The reasoning behind each one ships inside the block, so it travels with the code instead of living on a page you have to trust. A finding marked fixed was fixed after the audit ran; the verdict above is still the one the audit gave.

What you still have to do

The feature cannot own your secrets, your host or your legal obligations. This is the part it deliberately does not claim.

What lands in your project

vanilla

  • vanilla/affiliate.js

attachReferral() captures ?ref= into a bounded cookie AND stamps the click time into it; referral() reads back {code, referredAt} and referralCode() still returns just the code; affiliateLink(code) builds the share URL. Send BOTH values to your conversion endpoint: referredAt is what bounds the attribution window, and recordConversion() refuses a sale it cannot date. Framework-free, so a React page can call these directly.

node

  • node/affiliate-api.js

Express/Fastify-agnostic handlers: apply(), me(), recordConversion(), signReferral()/verifyReferral() for a server-signed click time, and the state moves approve(), setAffiliateStatus(), markPayable(), markPaid() and reverse(). Pure functions over a store you inject, so it drops onto any backend. apply() returns a dashboardToken once and stores only its hash; me() needs that token as well as the code. Pass a notify hook to apply(): it mails the confirmation token that verifyEmail() takes, and on a re-application it mails the code to the stored address.

sql

  • sql/affiliate.sql

affiliates + affiliate_conversions + affiliate_audit. The unique index on (affiliate_id, order_id) is what makes recordConversion idempotent under webhook retries.

What you supply

Get it

Download the Playground See pricing

A feature of the Vibe Coder Playground.

Questions

Is Affiliate and referral tracking audited?
It was audited on 2026-09-29, and the verdict was not a clean pass. 5 findings have been fixed since then, and the verdict stands until the block is audited again.
What do I still have to do myself?
The referral code is public, because it sits in every share link, so it cannot unlock earnings. me() refuses a bare code with a 401 and answers only when the caller also sends the dashboard token apply() returned at signup. Only a hash of that token is stored. Your dashboard page must keep the token and send it in a header. This holds until your app has real sessions; then check the session instead. A lost token cannot be recovered from the database, and this block ships no reset flow.
How do I get this?
It is a feature of the Vibe Coder Playground. Download the Playground, and see the pricing page for what each plan includes.

All Playground features · Free code blocks · Learn to build from zero · The coding guide