Docs for founders

Referral tracking setup

Affilicy never replaces your checkout. It reads payments from your Stripe account through the Affilicy Stripe App and decides which affiliate referred each paying customer. Promo codes work with Stripe alone; referral links also need one script on your website.

This guide as Markdown, for AI assistants

Connect Stripe and choose products

In Stripe & PayPal, install the Affilicy Stripe App on the account that bills your customers. Then open your app, go to Tracking and tick the products that belong to it. Payments for other products are ignored.

No webhooks or API keys to copy: the Stripe App sends Affilicy the payment events.

Choose promo codes, referral links or both

Promo codes

No script needed

Customers enter an affiliate's code at checkout and Stripe reports it. Your checkout only has to accept promotion codes.

Referral links

One script on your site

Visitors arrive through an affiliate's link. A small script on your site passes their code to Stripe, set up below.

Only using promo codes? You can skip the rest of this setup. Affiliates still get a link to share, but a click only counts once the script is on your site.

How a referral link reaches Stripe

  1. Affiliate link

    /r/max-1a2b

  2. Your websiteYour part

    ?via=max-1a2b

  3. Stripe checkout

    client_reference_id

  4. Commission

    On actual payments

Your website has one job: hand the referral code to Stripe when checkout starts. After the first payment the customer stays with that affiliate, so renewals and upgrades follow your program terms without a code or link.

Let your coding assistant install it
Run one command in your website's project folder. The assistant reads the Affilicy guide, finds where your checkout starts and shows you the changes before anything is committed.
Terminal
claude "Add Affilicy referral tracking to this project. Follow the guide at https://affilicy.com/docs/tracking.md?days=60 and show me the changes before you commit."

In the Claude desktop app or your IDE, send the text inside the quotes as your message instead.

Affilicy already connected to your assistant? Just ask: “Set up Affilicy tracking for my app in this project.” It reads your app's settings through the Affilicy connection.

Connect your AI
Or add it yourself
Three small changes to your website, then a quick test.
  1. Load the script on every page

    Add it once to your shared layout or site-wide head. data-days is how long a referral is remembered; use your program's cookie duration.

    HTML, in <head>
    <script src="https://affilicy.com/js/track" data-days="60" async></script>

    Webflow, Framer, WordPress and other builders: paste the HTML tag into the site-wide custom code for the head.

  2. Pass the code to Stripe

    Choose how your checkout starts. Using several? Cover each one.

  3. Connect your consent banner

    Remembering a referral in a visitor's browser is not strictly necessary for your site, so in the EU it needs consent (GDPR, TDDDG, ePrivacy). Until then the script stores nothing, and the code works only on the page the visitor landed on.

    Your consent banner
    // In your consent banner's "accepted" callback (marketing),
    // and on every page load once that consent is stored:
    window.Affilicy?.consent();

    No EU visitors, or another legal basis you have checked? Add data-consent="not-required" to the script tag to remember right away. Either way, list Affilicy referral tracking in your privacy policy.

  4. Test it

    Open your site with a test code, then check the browser console.

    https://yourapp.com/?via=test-code

    Browser console
    window.Affilicy.referral(); // "test-code"

    Then start a checkout in Stripe test mode. The Checkout Session shows test-code as its client reference ID or in metadata as affilicy_ref. No affiliate has that code, so nothing is attributed.

In the dashboard, your app's Tracking tab shows this guide with your website and attribution window filled in.

What earns commission

Affilicy looks for the referral in this order: an affiliate promotion code, then metadata.affilicy_ref on the subscription, invoice, customer or Checkout Session, then the session's client_reference_id.

  • Only paid invoices and paid one-time Checkout Sessions. Trials, $0 invoices and failed payments never do.
  • After the first payment the customer stays bound to the affiliate: renewals, upgrades and downgrades follow your program terms, with or without a discount on later invoices.
  • Commission is calculated on the tax-exclusive amount actually collected for your mapped products.
  • Refunds shrink or reverse unpaid commissions; disputes freeze them until resolved.
  • Each commission is recorded once per invoice, however often Stripe retries a webhook.