Lemon Squeezy Integration
Automatically track purchases and calculate commissions with Lemon Squeezy
Overview
Refgrow integrates with Lemon Squeezy to automatically track payments and calculate commissions for your affiliates.
- Automatic tracking of one-time payments and subscriptions
- Support for product-specific commission rates
- Support for affiliate-specific commission overrides
- Secure webhook implementation for real-time tracking
- Works with Lemon Squeezy checkout pages and hosted checkout
- Support for discount codes and coupon tracking
Setting Up Lemon Squeezy Integration
Step 1: Add the Refgrow Tracking Script
Insert this snippet into the <head>
of your site (any page where users land before purchasing):
<script src="https://refgrow.com/embed.js" data-project="YOUR_PROJECT_ID" async></script>
YOUR_PROJECT_ID
with your actual project ID from the Refgrow dashboard.
Step 2: Create a Webhook in Lemon Squeezy
- Go to Lemon Squeezy → Settings → Webhooks
- Click Create Webhook
- Configure the following settings:
Webhook Configuration
- URL:
https://refgrow.com/webhook/lemonsqueezy/YOUR_PROJECT_ID
- Events: Enable at least:
order_created
subscription_created
subscription_payment_succeeded
- Secret: Copy the webhook secret and save it in your project's integration settings
Step 3: Configure Webhook Secret
- Go to your project's "Integration" tab in Refgrow
- Select "Lemon Squeezy Webhooks" as your tracking method
- Paste the webhook secret from Lemon Squeezy
- Click "Save Integration Settings"
Passing Referral Codes
Method 1: Automatic Custom Data (Recommended)
For checkout links that users visit after clicking a referral link, Refgrow automatically modifies the URLs. Simply add the class refgrow-lemonsqueezy-link
to your links:
<a href="https://your-store.lemonsqueezy.com/checkout/buy/abc123" class="refgrow-lemonsqueezy-link">Buy Now</a>
Refgrow's tracking script will automatically:
- Check if a referral code exists in cookies
- Add
checkout[custom][referral_code]=CODE
to the link - Ensure proper attribution in Lemon Squeezy webhooks
Method 1b: Direct Custom Data in URL
You can also manually add the custom data parameter to Lemon Squeezy checkout links:
<a href="https://your-store.lemonsqueezy.com/checkout/buy/abc123?checkout[custom][referral_code]=ALEX123">Buy Now</a>
Refgrow.processLemonSqueezyLinks()
to process them automatically.
Method 2: Manual Custom Data
If you're creating checkout sessions programmatically, you can pass the referral code in custom data:
// Example API call to Lemon Squeezy
const checkoutData = {
// ... other checkout parameters
custom: {
referral_code: 'ALEX123'
}
};
Method 3: Discount Codes
You can also track affiliates using unique discount codes:
- Create discount codes in Lemon Squeezy for each affiliate
- In Refgrow, go to your project's "Coupons" tab
- Link each Lemon Squeezy discount code to an affiliate
- When customers use the discount code, commissions are automatically attributed
Commission Configuration
Default Commission Settings
Configure your default commission structure in your project settings:
- Commission Type: Percentage or Fixed Amount
- Commission Value: The percentage or fixed amount
- Commission Duration: Lifetime, First Purchase, or Limited Period
Product-Specific Commissions
Override commission rates for specific products:
- Go to your project's "Integration" tab
- Scroll to "Product-Specific Commissions"
- Click "Add Product Commission"
- Enter the Lemon Squeezy variant ID and set its unique commission rate
Affiliate-Specific Overrides
Set custom commission rates for individual affiliates:
- Go to your "Affiliates" tab
- Find the affiliate you want to customize
- Click "Manage Override"
- Set a custom commission type and value
How It Works
1. Referral Click
User clicks an affiliate link and the referral code is stored in a cookie.
2. Lemon Squeezy Payment
The referral code is passed to Lemon Squeezy via custom data, and the user completes payment.
3. Webhook Processing
Refgrow receives the webhook, attributes the sale, and calculates the commission.
Supported Webhook Events
Refgrow automatically listens for these webhook events:
order_created
- When a one-time purchase is completedsubscription_created
- When a new subscription is createdsubscription_payment_succeeded
- When a subscription payment is processed
Testing Your Integration
Test Steps
- Create a test affiliate in your Refgrow dashboard
- Generate a referral link for the test affiliate
- Click the referral link (this sets the tracking cookie)
- Complete a test purchase on Lemon Squeezy
- Check your Refgrow dashboard to confirm:
- The conversion was recorded
- The correct commission was calculated
- The affiliate's earnings were updated
Troubleshooting
- Verify your webhook secret is correctly set in your project settings
- Check that the webhook endpoint was created with the correct URL:
https://refgrow.com/webhook/lemonsqueezy/{your-project-id}
- Confirm all required events are enabled for the webhook
- Check your Lemon Squeezy dashboard for webhook delivery logs
- Ensure the webhook signature verification is working
- Ensure the Refgrow tracking script is installed on all pages
- Verify the referral code is being passed correctly (check custom data in Lemon Squeezy)
- Check that the cookie is being set (check browser developer tools)
- Confirm the affiliate's referral code matches exactly
- Verify the customer email in Lemon Squeezy matches the email used during signup (if applicable)
- Check webhook logs for any processing errors
Refgrow automatically prevents duplicate conversions by tracking:
- Lemon Squeezy Order ID
- Product/Variant ID
- Transaction timestamp
If you see duplicates, check your webhook configuration to ensure events aren't being sent multiple times.
Advanced Features
Manual Conversion Tracking
For custom checkout flows, you can manually track conversions:
// Track a manual conversion
if (window.Refgrow) {
Refgrow.track(purchaseAmount, 'purchase', 'customer@example.com');
}
Multi-Currency Support
Refgrow automatically handles different currencies from Lemon Squeezy:
- Commissions are calculated in the original transaction currency
- Dashboard displays amounts in your project's configured currency
- Conversion rates are handled automatically