> ## Documentation Index
> Fetch the complete documentation index at: https://doc.trackrev.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Product-led referrals (the widget)

> Turn every signed-in user into a referrer automatically with the in-app widget and referral API.

Beyond recruiting dedicated affiliates, TrackRev can turn **every user of your product** into a
referrer — the "invite a friend, you both get credit" model. It's powered by a small in-app widget
and two API endpoints, and it pairs naturally with [credit rewards](/affiliate/credits-and-fulfilment).

## The two-sided model

<Steps>
  <Step title="Enroll each user as a referrer">
    When a user signs in, the widget (or a server call) enrolls them into your programme and mints
    their personal referral link — no application needed.
  </Step>

  <Step title="They share their link">
    Their referral link (and optional promo code) is theirs to share. Referred visitors are tracked
    like any other click.
  </Step>

  <Step title="A referred signup rewards both sides">
    When a referred person signs up, you report it to TrackRev. The inviter earns their reward, and
    (optionally) the new user gets a referee bonus.
  </Step>
</Steps>

## Embed the widget

Add the widget script to your app, authenticated with a **publishable** key:

```html theme={null}
<script
  src="https://app.trackrev.io/widget.js"
  data-key="pk_live_..."
  data-user-id="USER_ID"
  data-user-email="user@example.com"
  data-user-tier="paid"
></script>
```

* `data-key` — a publishable key from **Settings → Developers** (safe in the browser).
* `data-user-id` — your stable user id (`external_user_id`).
* `data-user-email` / `data-user-tier` — the user's email and `free` / `paid` tier, which
  determines their reward amount.

The widget enrolls the user and gives them their referral link and share UI.

## Or drive it with the API

Prefer to build your own UI? Call the referral endpoints directly:

* **Enroll** a user as a referrer: [`POST /api/v1/referrals/enroll`](/developers/endpoints/referrals#enroll-a-referrer).
* **Report a signup** attributed to a referrer: [`POST /api/v1/referrals/report-signup`](/developers/endpoints/referrals#report-a-signup).

Both accept a publishable **or** secret key. `report-signup` resolves the referrer from a
`ref_code`, a `_vid`, or an explicit referrer id, and runs [self-referral
checks](/affiliate/fraud-detection) before granting a reward.

<Info>
  The full referral flow — enroll, report, reward, credit fulfilment, self-referral protection —
  is covered end-to-end in the [API reference](/developers/endpoints/referrals) and
  [Credits & fulfilment](/affiliate/credits-and-fulfilment).
</Info>
