Refgrow

Tracking Setup

Learn how to track referrals and conversions with Refgrow.

How Tracking Works

Refgrow uses a combination of URL parameters and cookies to track referrals and attribute conversions accurately. Here is how it works:

1. Referral Link

Affiliate shares their unique referral link with the ref parameter.

2. Click Tracking

When someone clicks the link, Refgrow records the click and sets a tracking cookie.

3. Conversion

When the user converts (signs up, makes a purchase), the conversion is tracked.

4. Attribution

The conversion is attributed to the affiliate based on the tracking cookie.

Setting Up Basic Tracking

1. Add Tracking Script

First, add the Refgrow tracking script to your website:

html
<!-- Add this to the <head> section of your pages -->
<script
  src="https://scripts.refgrowcdn.com/latest.js"
  data-project-id="YOUR_PROJECT_ID"
  async defer>
</script>

2. Track Conversions

There are several ways to track conversions with Refgrow:

Manual Tracking

javascript
// Track a signup
Refgrow(0, 'signup', 'user@example.com');

// Track a purchase
Refgrow(99.99, 'purchase', 'user@example.com');

// Track a purchase with the payment's own id and currency
Refgrow(24000, 'purchase', 'user@example.com', {
  reference: 'txn_8f21c0',
  currency: 'XOF'
});

Parameters:

  • value: The monetary value of the conversion (use 0 for non-monetary conversions like signups)
  • type: The type of conversion ('signup' or 'purchase')
  • email: The email of the user who completed the conversion
  • options: Optional fourth argument, described below

Options

Worth setting on purchases, particularly when the call runs on an order confirmation page.

  • reference: Your own id for the payment, for example the transaction id from your payment provider. Refgrow records a conversion with a given reference once, so a customer refreshing the confirmation page cannot pay the affiliate twice for one sale.
  • currency: Three letter code for what the customer actually paid, for example EUR or XOF. Defaults to your project currency. Refgrow never converts between currencies: balances and payouts stay in the currency the commission was earned in.
  • couponCode: The discount code used at checkout, when you attribute by coupon rather than by referral link.
Note: This call runs in the visitor's browser, so it is missed if they close the tab before the page loads. If the conversion is a payment and you have API access, record it from your backend with POST /api/v1/conversions instead, which does not depend on the customer staying on the page.
Commissions reported from the browser wait for your approval. Anyone can send this call with any amount, so a purchase (or any conversion that earns a commission) reported this way is held in Fraud Review until you release it, and it is never paid by automatic payouts. A payment provider connected to Refgrow (Stripe, Paddle, Lemon Squeezy, Polar, Dodo) needs none of this. To have your own records approved automatically, send them from your server with an API key (Settings → API keys): either POST /api/v1/conversions, or this same endpoint (POST https://refgrow.com/api/track-conversion) with an Authorization: Bearer rgk_… header. Never put the key in browser code.

Configuration Options

The script reads data-project-id from its tag. Set the referral parameter name and cookie lifetime in your project settings. The script does not read data-param, data-cookie-days, or data-cookie-domain.

AttributeDefaultDescription
data-project-id—Required. Your Refgrow project ID.

Script Tag

html
<script
  src="https://scripts.refgrowcdn.com/latest.js"
  data-project-id="YOUR_PROJECT_ID"
  async defer>
</script>

With the default project settings, referral links use ?ref=CODE and the referral cookie lasts 30 days. A different parameter name or lifetime must be saved in the dashboard.

Integration with Payment Processors

Stripe Integration

To integrate with Stripe:

  1. Go to your project settings
  2. Click "Create Stripe API Key" button or enter your existing key
  3. The system will automatically configure webhooks and start tracking your Stripe payments
Note: See the Stripe integration guide for detailed setup instructions including attribution methods and Payment Links support.

LemonSqueezy Webhook Setup

  1. Go to your LemonSqueezy Dashboard → Settings → Webhooks
  2. Click "Add webhook"
  3. Set the webhook URL to: https://refgrow.com/webhook/lemonsqueezy/YOUR_PROJECT_ID
  4. Replace YOUR_PROJECT_ID with your actual project ID
  5. Select the following events:
    • order_created
    • subscription_created
    • subscription_updated
  6. Click "Create webhook" to save
Ensure you have set your LemonSqueezy API Key in your project settings.

Cookie Lifetime Configuration

You can configure how long the referral tracking cookie lasts in your project settings:

  1. Go to your project settings
  2. Find the "Cookie Lifetime" setting
  3. Set the number of days you want the tracking cookie to last
  4. Save your settings

The default cookie lifetime is 30 days. This means that if a user clicks an affiliate link, the referral cookie expires after 30 days unless you change the setting. The script also stores the code in localStorage together with the time of the click, so it can put back a cookie the browser removed early, for the days left of the cookie lifetime. A stored code older than the cookie lifetime is never used or restored; the script deletes it the next time it runs on your site.

Cross-Domain Tracking

If your marketing site (e.g., yoursite.com) and your app (e.g., app.yoursite.com or dashboard.yourproduct.io) are on different domains, you need cross-domain tracking.

Same root domain

The script sets the cookie for the detected root domain, so it can be read by subdomains of that root. Verify the cookie domain in your browser for your domain, especially if it uses a multi-part public suffix.

Different domains

Cookies and localStorage do not cross unrelated root domains. Pass the referral code in the URL or your checkout data when visitors move between them, then load the tracking script on the destination site.

Setting Up Your Tracking Domain

For optimal tracking, you can configure a custom tracking domain:

  1. Go to your project settings
  2. Find the "Tracking Domain" setting
  3. Enter your domain (e.g., yourdomain.com)
  4. Save your settings

Using your own domain for tracking can improve conversion rates and build trust with your customers.

Reading the Referral Cookie

To pass the referral code to your payment processor or backend:

javascript
// JavaScript (client-side)
function getRefgrowRef() {
  const match = document.cookie.match(
    /(?:^|;\s*)refgrow_ref_code_YOUR_PROJECT_ID=([^;]*)/
  );
  return match ? decodeURIComponent(match[1]) : null;
}

const referralCode = getRefgrowRef();
if (referralCode) {
  // Pass to your checkout or signup flow
  console.log('Referred by:', referralCode);
}

Server-Side Tracking

You can also read the referral cookie on the server side. For example, in Node.js/Express:

javascript
app.post('/checkout', async (req, res) => {
  const referralCode = req.cookies['refgrow_ref_code_YOUR_PROJECT_ID']
    || req.cookies.refgrow_ref_code; // legacy Refgrow.setReferral cookie
  // Pass referralCode in your payment provider's checkout metadata.
});

Content Security Policy

If your site uses a Content Security Policy (CSP), add Refgrow to your allowed sources:

bash
Content-Security-Policy:
  script-src 'self' https://scripts.refgrowcdn.com https://refgrow.com;
  connect-src 'self' https://refgrow.com;

Best Practices

Security

  • Ensure your tracking script is loaded over HTTPS
  • Validate conversion data on your server
  • Review tracking logs regularly
  • Keep your API keys secure

Performance

  • Place the tracking script in the <head> section
  • Track the most valuable conversion points
  • Test your tracking setup thoroughly
  • Monitor tracking for any issues

Privacy & GDPR

The tracking script sets a first-party cookie scoped to your domain. It does not use third-party cookies, fingerprinting, or cross-site tracking. The cookie contains the referral code and is not used for advertising. The script also uses localStorage for referral codes and, when supplied in the URL, an email or partner identifier. On load it requests project tracking settings from Refgrow; with a valid referral code in the URL it validates the code and sends attribution and click requests. The normal referral cookie uses Path=/ and an expiry based on the project setting. The script does not explicitly set SameSite, Secure, or HttpOnly on that cookie.

If you need to delay cookie creation until consent is given, you can load the script conditionally after the user accepts cookies.

Important Notes

  • The tracking script must be included on all pages where you want to track referral clicks and conversions.
  • For manual tracking, ensure that you call the Refgrow function after the tracking script has loaded and when you are certain the conversion has occurred.
  • Handle any errors that may occur during the tracking process to ensure a smooth user experience.
  • You can change the conversion tracking method in your project settings at any time.

Next Steps

Start Free Trial
Tracking Setup — Refgrow Docs