Get Started
Get Started with SweetRef
Welcome to SweetRef! This guide will help you set up your referral program quickly and easily.
Quick Start
- Create your free account.
- Set up your program details.
- Add the SweetRef script to your website.
- Configure event tracking.
- Launch your referral program!
Installation
1. Add the Script
Place the following script in your website's <head>
section:
<script
src="https://sweetref.com/sweetref.js"
program-id="YOUR_PROGRAM_ID"
rel="preload"
></script>
Replace
YOUR_PROGRAM_ID
with the ID provided during onboarding.
Event Tracking
To ensure accurate tracking of referrals, you need to read the sweet_ref
from the user's cookies and include it as REFERRAL_CODE
in your signup and payment tracking requests.
Reading the sweet_ref
Cookie
Add the following function to read the sweet_ref
value:
function getSweetRefCookie() {
const nameEQ = encodeURIComponent("sweet_ref") + "=";
const cookies = document.cookie.split("; ");
for (const cookie of cookies) {
if (cookie.indexOf(nameEQ) === 0) {
return decodeURIComponent(cookie.substring(nameEQ.length));
}
}
return null;
}
const referralCode = getSweetRefCookie();
1. Track User Signups
When a user signs up, track the event and include the REFERRAL_CODE
:
fetch("https://api.sweetref.com/events", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({
event: "signup",
data: {
user_id: "USER_ID",
user_email: "USER_EMAIL",
user_name: "USER_NAME",
ref_code: referralCode,
},
}),
});
2. Track Payments
Record successful payments to attribute them to the correct referrer:
fetch("https://api.sweetref.com/events", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({
event: "payment",
data: {
user_id: "USER_ID",
payment_id: "PAYMENT_ID",
amount: "AMOUNT",
currency: "CURRENCY",
},
}),
});
3. Track Refunds
Record any refunds to maintain accurate program statistics:
fetch("https://api.sweetref.com/events", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({
event: "refund",
data: {
payment_id: "PAYMENT_ID",
},
}),
});
Note: Replace all placeholder values (
USER_ID
,YOUR_API_KEY
, etc.) with your actual data.
Verification
After installation, check for a sweet_ref
cookie in your browser to confirm proper setup. This cookie stores the referral code and should be included in your signup tracking request as ref_code
.