Manual Integration
For businesses not using Stripe or requiring custom integration, Endorsely offers a manual integration method using our API.
Integration Steps
Step 1: Add our script to your website
Add this script to the <head>
section of every page on your site where you want to track referral clicks:
<script
async
src="https://assets.endorsely.com/endorsely.js"
data-endorsely="<your-organization-id>"
></script>
If you use a cookie tool on your website that automatically removes tracking cookies without consent, you will need to whitelist Endorsely's cookie to allow affiliate clicks to be tracked.
Step 2: Generate an API Secret
In your Endorsely dashboard, navigate to the API section to generate an API secret key.
Keep your API secret secure and never expose it in frontend code. It should only be used in your backend.
Step 3: Implement Referral Tracking
Referral tracking involves two parts:
- Frontend: Capture the referral ID when a user clicks a referral link
- Backend: Track conversions (signups, purchases) and associate them with referrals
Frontend Implementation (JavaScript)
// Access the referral ID
const referralId = window.endorsely_referral;
// If there's a referral ID, send it to your backend
if (referralId) {
// Example: Storing in localStorage (adjust based on your needs)
localStorage.setItem("endorsely_referral", referralId);
// Example: Sending to your backend immediately
fetch("/api/store-referral", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ referralId }),
});
}
Backend Implementation
When a referred user completes an action (e.g., signs up or makes a purchase), call our API from your backend to record the referral:
const axios = require("axios");
async function trackReferral(referralId, email, amount) {
try {
const response = await axios.post(
"https://app.endorsely.com/api/public/refer",
{
referralId,
organizationId: "<your-organization-id>",
email, // optional
amount: amount * 100, // Convert to cents
name: "<referred-user-name>", // optional
customerId: "<your-system-customer-id>", // optional
},
{
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_SECRET",
},
}
);
console.log("Referral tracked successfully:", response.data);
} catch (error) {
console.error(
"Error tracking referral:",
error.response?.data || error.message
);
}
}
// Initial purchase tracking
app.post("/complete-purchase", async (req, res) => {
const { email, amount, referralId } = req.body;
if (referralId) {
await trackReferral(referralId, email, amount);
}
// Rest of your purchase completion logic
});
// Example: Tracking recurring payment
app.post("/process-recurring-payment", async (req, res) => {
const { email, amount, referralId } = req.body;
if (referralId) {
// This will add to the existing totals
await trackReferral(referralId, email, amount);
}
// Rest of your payment processing logic
});
Important Notes
- Multiple tracking calls for the same referral ID will accumulate payment amounts and commissions automatically.
- Optional fields (name, customerId) will be updated if provided in subsequent calls.
- Each tracking call will calculate and add commissions based on your campaign settings.
- This accumulation feature makes it easy to track recurring revenue or multiple purchases from referred customers.