Documentation

Add a referral tab to your app

Three pieces: a script on every page, a signed token that says who's looking, and the <reftab-tab> element. Everything else happens in your Stripe account.

Quick start#

  1. Sign up, enter your product URL and pick a reward preset.
  2. Paste the script tag into your marketing site and your app.
  3. Add a server endpoint that signs a user token with your secret key.
  4. Render <reftab-tab token=…> on a “Refer a friend” page.
  5. Call Reftab.signup() after signup, and connect Stripe.
<script src="https://reftab.app/reftab.js" data-key="rt_pub_live_…" defer></script>

<reftab-tab token="SIGNED_USER_TOKEN"></reftab-tab>
Using Claude Code or Cursor? The Install page in your dashboard has a copy-paste prompt with your keys filled in.

The script tag#

Load reftab.js on every page, including your marketing site. When a visitor arrives with ?ref=CODE (or ?via=CODE), it records the click and stores the referral for the program's cookie window (60 days by default) in a first-party cookie and localStorage. First click wins: a later link doesn't steal the attribution. The cookie is written on your root domain, so a referral captured on acme.com is still known on app.acme.com.

AttributeDescription
data-keyYour public key: rt_pub_test_… or rt_pub_live_…. Safe to ship to browsers.
data-banner"true" shows a welcome banner to referred visitors.
data-apiOverride the API origin (self-hosting).

User tokens#

The tab needs to know which of your users is looking at it. Your backend vouches for them with a standard HS256 JWT signed with your secret key (rt_sec_…). Never expose the secret key in the browser.

ClaimRequiredDescription
subYesYour user id. Their referral link is tied to it.
emailYesUsed to match them to their Stripe customer for rewards.
nameNoUsed for their code (SARAH) and greeting.
expRecommendedExpiry as a Unix timestamp. One hour is plenty.
import { createHmac } from "node:crypto";

const b64 = (v: object) => Buffer.from(JSON.stringify(v)).toString("base64url");

export function reftabToken(user: { id: string; email: string; name?: string }) {
  const now = Math.floor(Date.now() / 1000);
  const body = `${b64({ alg: "HS256", typ: "JWT" })}.${b64({
    sub: user.id, email: user.email, name: user.name, iat: now, exp: now + 3600,
  })}`;
  const sig = createHmac("sha256", process.env.REFTAB_SECRET_KEY!).update(body).digest("base64url");
  return `${body}.${sig}`;
}

<reftab-tab> and <reftab-launcher>#

<reftab-tab> is a web component rendered in Shadow DOM, so your CSS and ours never collide. It inherits your font, takes your brand colours from the dashboard, supports light and dark mode and adapts to narrow containers. The first time a user opens it, their referral link is created.

AttributeDescription
tokenThe signed user token. Changing it reloads the tab.
programOptional program id, for projects with several programs (Pro).
theme"light", "dark" or "auto". Overrides the dashboard setting.

<reftab-launcher> adds a floating “Refer & earn” button that opens the tab in a side panel. It takes token, label, color and position (left or right).

"use client";
import { useEffect, useState } from "react";

export function ReferralTab() {
  const [token, setToken] = useState<string | null>(null);
  useEffect(() => {
    fetch("/api/reftab-token").then((r) => r.json()).then((d) => setToken(d.token));
  }, []);
  return token ? <reftab-tab token={token} /> : null;
}

declare module "react" {
  namespace JSX {
    interface IntrinsicElements {
      "reftab-tab": { token?: string; program?: string; theme?: string };
      "reftab-launcher": { token?: string; label?: string; color?: string; position?: string };
    }
  }
}

The element emits a reftab:loaded event with the tab data, and exposes part="container" and part="button" for ::part() styling.

JavaScript API#

MethodDescription
Reftab.signup({ email, userId, name })Report a signup from the browser. Matches the stored click. Returns a promise of { attributed }.
Reftab.visitorId()The anonymous visitor id. Pass it to your backend or as Stripe Checkout client_reference_id.
Reftab.referral()The stored referral ({ code, clickId, … }) or null.
Reftab.ready(cb)Runs after the click is recorded. Also fires a reftab:ready event on document.
Reftab.open(token)Opens the tab in a side panel.

Browser signups are safe: rewards only happen when that email becomes a paying Stripe customer. Prefer the server? Use POST /api/v1/referrals with the visitor id.

Stripe connection#

Create a restricted key with these permissions and paste it on the Install page. Use a test key (rk_test_) for test mode and a live key for live mode.

ResourcePermission
CustomersWrite
Customer balance transactionsWrite
CouponsWrite
Promotion codesWrite
SubscriptionsWrite
Subscription schedulesWrite
InvoicesRead
Charges and refundsRead
Payment methodsRead
Webhook endpointsWrite

We register a webhook endpoint in your account for: invoice.paid, charge.refunded, customer.created, customer.subscription.updated, customer.subscription.deleted, checkout.session.completed. Developing locally? Forward events with the Stripe CLI and paste the whsec_ secret it prints:

stripe listen --forward-to https://reftab.app/api/stripe/webhook/<projectId>/test

How payments are matched

  • By the Stripe customer linked at signup (stripeCustomerId), then by email.
  • By promotion code: when the friend's reward is a discount, each referrer's code (e.g. SARAH) is also a Stripe promotion code. Enable allow_promotion_codes in Checkout.
  • By metadata: reftab_code or reftab_visitor on the customer or Checkout Session, or the visitor id as client_reference_id.

Test mode and simulator#

Every project has separate test and live data, and separate keys. In test mode without a Stripe test key, rewards run against a built-in sandbox that behaves like Stripe. The dashboard's simulator drives the real code paths: a friend clicks, signs up and pays; you can refund or cancel them, and skip the hold period to watch rewards apply.

Reward types#

TypeHow it's applied
Free month(s)Credit on the customer balance worth their monthly price
Percentage discountStripe coupon on their subscription
Fixed discountStripe coupon on their subscription
Account creditCredit on the Stripe customer balance
Plan upgradeSubscription schedule that switches plans, then switches back
Cash commissionPaid from your PayPal or Wise in a payout batch

Rewards can go to the referrer, the friend, or both. A cap per referrer is optional. Cash commissions (Pro) are a percentage of every paid invoice for a number of months, batched into PayPal Payouts or Wise batch files that you upload yourself.

Hold period and fraud rules#

Rewards are created on the friend's first paid invoice and released after the hold period (30 days by default). A refund or cancellation inside the hold period cancels them. Every reward has a status: pending, approved, applied, paid, cancelled or failed, with the reason. Switch a program to “approve manually” to review each one.

SignalWhat happens
Same email as the referrerReferral blocked, no rewards
Same Stripe customer as the referrerReferral blocked, no rewards
Same card as the referrerReferral blocked, no rewards
Signed up from the referrer's networkRewards held for your approval
Many signups from this referrer in a short timeRewards held for your approval
Disposable email addressRewards held for your approval

REST API#

Authenticate with your secret key as a Bearer token. Test and live keys see their own data. Reporting signups and payments and minting user tokens are free; listing endpoints are part of Pro.

EndpointDescription
POST /api/v1/user-tokenMint a one-hour tab token for a user.
POST /api/v1/referralsReport a signup with visitorId, clickId or code.
GET /api/v1/referralsList referrals. ?status=converted&limit=50 (Pro)
POST /api/v1/referrersGet or create a user's link and code.
GET /api/v1/referrersReferrers ranked by revenue. ?search= (Pro)
GET /api/v1/rewardsList rewards. ?status=pending (Pro)
GET /api/v1/statsHeadline numbers (Pro).
POST /api/v1/conversionsReport a payment Reftab can't see in Stripe. Idempotent on invoiceId.
curl https://reftab.app/api/v1/referrals \
  -H "Authorization: Bearer $REFTAB_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"email":"tom@example.com","userId":"user_456","visitorId":"v_8f2c…"}'

Errors look like { "error": { "message": "…", "code": "…" } }.

Outgoing webhooks#

Set a webhook URL in Settings (Pro) and we'll POST JSON events: referral.created, referral.converted, referral.refunded, referral.churned, reward.created, reward.applied, reward.cancelled, payout.created, payout.paid, partner.joined. Each request carries a Reftab-Signature: t=…,v1=… header: an HMAC-SHA256 of `${t}.${body}` with your webhook secret, the same scheme as Stripe.

import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyReftab(body: string, header: string, secret: string) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const expected = createHmac("sha256", secret).update(`${parts.t}.${body}`).digest("hex");
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
  return fresh && timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 ?? ""));
}

MCP server#

Everything the dashboard does, an agent can do. The server speaks the Streamable HTTP transport at https://reftab.app/api/mcp and authenticates with your secret key as a Bearer token (Pro). A test key works on test data, a live key on live data. The Install page creates a key and fills it into these snippets for you.

claude mcp add --transport http reftab https://reftab.app/api/mcp --header "Authorization: Bearer rt_sec_live_…"
ToolWhat it does
get_overviewHeadline numbers: referred MRR, paying referrals, revenue, rewards given and their cost, plus the last 30 days.
list_referrersReferrers ranked by the revenue they brought.
list_referralsRecent referrals (people who signed up through a link or code) with their status.
list_rewardsRewards with status pending, approved, applied, paid, cancelled or failed.
get_programThe current referral program and a plain-language preview of its rules.
update_programChange the referral program. Pass a preset (give_month, twenty_off, credit, affiliate) and/or individual fields. Values: free_month value = months; percent_discount value = percent; fixed_discount and credit value = cents.
approve_rewardApprove and apply a pending reward now, skipping any remaining hold period.
cancel_rewardCancel a pending, approved or failed reward with a reason.
create_referral_linkGet or create the referral link and code for one of your users.
get_top_sourcesWhere referral traffic comes from: by channel (X, LinkedIn, YouTube…) or by individual post, with revenue per post.
get_install_instructionsStep-by-step instructions and code to add the referral tab to the app: script tag, user-token endpoint, the <reftab-tab> element and the signup call.
get_setup_statusWhat is set up and what is left (reward, brand, tab installed, Stripe, webhooks, first referral), with the next step. Call it after installing to verify the work.
get_referrerOne referrer with their link, stats, the people they referred and their rewards. Look them up by id, code or email.
simulate_referralTest mode only. Runs a fake referral through the real pipeline: a link click, a signup and (unless pay is false) a first payment that creates pending rewards. Use it to check an install end to end.
release_held_rewardsTest mode only. Ends the hold period for every pending test reward and applies them now (in the sandbox or your test Stripe).

Prompts, for clients that support them (in Claude Code, type /mcp__reftab__install_reftab):

PromptWhat it does
install_reftabWalks your coding agent through adding the script, the user-token endpoint, the referral tab and signup reporting, then verifies the install.
referral_reportA short report on what referrals brought in: revenue, best referrers, best posts and anything that needs attention.
review_rewardsGoes through pending and failed rewards, explains each one and asks before approving or cancelling.
tune_programLooks at the current program and the numbers, then suggests a better reward with the trade-offs.
Try: “Add the Reftab referral tab to this app, then check the install.” The agent calls get_install_instructions, edits your code, then get_setup_status to confirm. In test mode, simulate_referral and release_held_rewards run the whole loop without real payments.