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

Note: You'll need a Lemon Squeezy account to track payments. If you don't have one, sign up here.

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>
Important: Replace YOUR_PROJECT_ID with your actual project ID from the Refgrow dashboard.

Step 2: Create a Webhook in Lemon Squeezy

  1. Go to Lemon Squeezy → Settings → Webhooks
  2. Click Create Webhook
  3. 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

  1. Go to your project's "Integration" tab in Refgrow
  2. Select "Lemon Squeezy Webhooks" as your tracking method
  3. Paste the webhook secret from Lemon Squeezy
  4. Click "Save Integration Settings"

Passing Referral Codes

Tip: There are multiple ways to pass referral codes to Lemon Squeezy for proper attribution.

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>
Note: If you're adding Lemon Squeezy links dynamically after page load, call 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:

  1. Create discount codes in Lemon Squeezy for each affiliate
  2. In Refgrow, go to your project's "Coupons" tab
  3. Link each Lemon Squeezy discount code to an affiliate
  4. 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:

  1. Go to your project's "Integration" tab
  2. Scroll to "Product-Specific Commissions"
  3. Click "Add Product Commission"
  4. Enter the Lemon Squeezy variant ID and set its unique commission rate
Note: Product-specific rates take priority over your default commission settings.

Affiliate-Specific Overrides

Set custom commission rates for individual affiliates:

  1. Go to your "Affiliates" tab
  2. Find the affiliate you want to customize
  3. Click "Manage Override"
  4. Set a custom commission type and value
Priority: Affiliate-specific overrides take highest priority, followed by product-specific commissions, with default settings as the fallback.

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 completed
  • subscription_created - When a new subscription is created
  • subscription_payment_succeeded - When a subscription payment is processed

Testing Your Integration

Quick Test: Use a test purchase to verify everything is working correctly.

Test Steps

  1. Create a test affiliate in your Refgrow dashboard
  2. Generate a referral link for the test affiliate
  3. Click the referral link (this sets the tracking cookie)
  4. Complete a test purchase on Lemon Squeezy
  5. Check your Refgrow dashboard to confirm:
    • The conversion was recorded
    • The correct commission was calculated
    • The affiliate's earnings were updated

Troubleshooting

  1. Verify your webhook secret is correctly set in your project settings
  2. Check that the webhook endpoint was created with the correct URL: https://refgrow.com/webhook/lemonsqueezy/{your-project-id}
  3. Confirm all required events are enabled for the webhook
  4. Check your Lemon Squeezy dashboard for webhook delivery logs
  5. 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

Next Steps

Using the Tracking Script

Learn more about Refgrow's client-side tracking.

View Guide
Commissions

Understand how commission calculations work.

View Guide
Managing Affiliates

Learn how to manage your affiliate program.

View Guide