In-app referral widget

Show signed-in customers their own referral link, code, share buttons, progress and their friends' reward inside your app.

Embed
Preview of the card
<a href="https://referalli.com/docs/referral-widget"><img src="https://referalli.com/docs/_api/public/orgs/07f432f4-34b9-46a7-aaad-c0e395d2e4f9/spaces/2bf4f614-3630-4fbf-85f9-5ecafa6b7d97/pages/503155a7-eaf3-4acc-a064-e0e212f67d6d/social-card.svg?v=3e7ae33eec8b" alt="In-app referral widget" width="600" height="315"></a>

The referral widget is a web component you put in your own app. It shows the signed-in customer, as a referrer, their referral link, their code, share buttons, how many people clicked, signed up and paid, what they've earned, and the reward their friends get. It's translated into the dashboard's 10 languages.

Your backend mints a short-lived token for the customer; the widget uses it to read that one customer's details. Your API key never reaches the browser, and a token can't read anyone else's data.

1. Add the widget

<script src="https://referally.15.204.158.166.sslip.io/t/tk_.../widget.js" async></script>
<referally-referral-widget token-url="/api/referally-widget-token"></referally-referral-widget>

Attribute

Meaning

token-url

An endpoint on your server that returns { "token": "…" } for the signed-in customer. The widget calls it with your site's cookies (credentials: "include").

token

Alternatively, a token you rendered into the page.

lang

en, es, de, fr, pt, it, nl, sv, ja or zh. Defaults to the page's <html lang>, then the browser's language.

Or mount it from JavaScript: Referally.mountReferralWidget(element, { tokenUrl, lang }). The element is also available as <referally-widget-referrer>.

2. Mint the token on your server

POST /v1/widget/tokens with an API key:

// GET /api/referally-widget-token, for the signed-in user
const res = await fetch(`${REFERALLY}/v1/widget/tokens`, {
  method: 'POST',
  headers: { authorization: `Bearer ${process.env.REFERALLY_API_KEY}`, 'content-type': 'application/json' },
  body: JSON.stringify({ programId: 'prg_...', customerRef: user.id, email: user.email }),
});
return Response.json(await res.json()); // { token, partnerId, expiresAt }

Field

Required

Description

programId

yes

The program whose link and reward the widget shows.

customerRef or partnerExternalRef

one of them

The customer, as the partner's externalRef (customers who are also partners, e.g. auto-enrolled through Atlas).

email, displayName

for on-demand creation

Used only when the program creates the partner on demand (below).

ttlSeconds

no

60 to 3600; default 900.

Responses: 404 when no approved partner in the program has that externalRef (and on-demand creation is off), 400 when on-demand creation needs an email, 404 for a banned or archived partner.

Create partners on demand

To give every customer a referral link the first time they open the widget, turn on settings.widget for the program (dashboard: program page → In-app referral widget):

curl -X PATCH $BASE/v1/programs/prg_... -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
  -d '{"widget": {"autoEnroll": true, "destinationUrl": "https://yourapp.com/signup"}}'

The partner is created with externalRef = the customer, enrolled, and given an 8-character code as a coupon and, with destinationUrl, a link.

What the widget reads

GET /t/{trackingToken}/widget/me with Authorization: Widget <token> (public, CORS-enabled):

{
  "program": { "id": "prg_...", "name": "Acme Friends" },
  "partner": { "displayName": "Dana" },
  "code": "dana",
  "coupon": "DANA10",
  "link": "https://go.acme.com/go/tk_.../dana",
  "share": { "x": "…", "facebook": "…", "linkedin": "…", "whatsapp": "…", "email": "mailto:…" },
  "progress": { "clicks": 12, "signups": 3, "payingCustomers": 1 },
  "earnings": [{ "currency": "usd", "pending": 1980, "approved": 0, "paid": 0 }],
  "refereeReward": { "kind": "store_credit", "bps": 200, "capMinor": 500, "currency": "usd", "on": "first_payment" }
}

No email address is ever returned. An expired, tampered or other-merchant token gets 401, and so does a token for a partner who was since banned or archived.

Theming

The widget renders in a shadow root. Style it with CSS variables on the element:

referally-referral-widget {
  --referally-accent: #4f46e5;
  --referally-bg: #ffffff;
  --referally-fg: #111827;
  --referally-muted: #6b7280;
  --referally-border: #e5e7eb;
  --referally-radius: 12px;
  --referally-font: Inter, system-ui, sans-serif;
}

The outer box is exposed as ::part(box).

Updated