A single block you can paste into Cursor, Copilot, or any AI coding assistant. The AI will understand the instructions and apply the integration to your codebase.
Copy the full guide below and paste it into your AI chat. Replace the placeholders with your actual values.
# Referish Integration Guide (Copy this to your AI assistant)
Integrate Referish affiliate tracking into your SaaS. Replace placeholders with your values.
## Your values (replace these)
- EASY_AFFILIATION_APP_URL: http://localhost:3000
- YOUR_ACCOUNT_ID: (get from Referish dashboard → Integrations)
- YOUR_SIGNUP_URL: (e.g. https://app.yoursaas.com/signup or https://yoursaas.com/pricing)
---
## 1. Add "Become an affiliate" page
Create a page at /affiliates or /partners with this link:
```html
<a href="http://localhost:3000/portal/join?account=YOUR_ACCOUNT_ID" target="_blank" rel="noopener">
Become an affiliate
</a>
```
Replace YOUR_ACCOUNT_ID with your actual account ID from the Referish dashboard.
---
## 2. Capture ref parameter on landing pages
When a customer arrives from an affiliate link (e.g. yoursite.com/pricing?ref=ABCD1234), capture the ref and store it. Add this to your signup/pricing page or a shared layout that runs on pages where affiliates send traffic:
```javascript
// Run on page load - captures ?ref=CODE from URL and stores in cookie
const params = new URLSearchParams(window.location.search);
const ref = params.get('ref');
if (ref) {
document.cookie = `affiliate_ref=${ref}; path=/; max-age=2592000`;
}
```
For server-side (Next.js, etc.), also read ref from the request and store in session/cookie so it persists to checkout.
---
## 3. Pass ref to Stripe at checkout
When creating a Stripe customer or subscription, add the ref to metadata. Read it from your cookie/session:
```javascript
// Client-side: read ref from cookie
const ref = document.cookie.match(/affiliate_ref=([^;]+)/)?.[1];
// Server-side: when creating Stripe customer
const customer = await stripe.customers.create({
email: customerEmail,
metadata: {
ref: refCode || undefined, // refCode from cookie/session
},
});
// Or when creating a subscription
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{ price: priceId }],
metadata: {
ref: refCode || undefined,
},
});
```
Supported Stripe metadata keys: ref, ref_code, or affiliate_id (UUID).
---
## 4. Optional: Resolve ref to affiliate_id
If you prefer to pass affiliate_id instead of ref_code:
```
GET http://localhost:3000/api/attribution/resolve?ref=ABCD1234&accountId=YOUR_ACCOUNT_ID
Response: { "affiliateId": "uuid", "refCode": "ABCD1234" }
```
Then use metadata: { affiliate_id: response.affiliateId } in Stripe.
---
## 5. Flow summary
1. Affiliate shares: YOUR_SIGNUP_URL?ref=THEIR_CODE (each affiliate has unique code)
2. Customer lands → ref captured and stored in cookie/session
3. At checkout → pass ref (or affiliate_id) in Stripe customer/subscription metadata
4. Referish webhook reads metadata on invoice.paid → creates commission
5. Affiliate gets paid via Stripe Connect
---
## Checklist
- [ ] Add Become an affiliate link (replace YOUR_ACCOUNT_ID)
- [ ] Add ref capture code to landing pages
- [ ] Pass ref to Stripe metadata when creating customer/subscription
- [ ] Set signup URL in Referish Settings (YOUR_SIGNUP_URL)
- [ ] Stripe webhook: enable "Listen to events on connected accounts"