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');

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

Configuration Options

Customize tracking behavior with data attributes on the script tag:

AttributeDefaultDescription
data-project-idRequired. Your Refgrow project ID.
data-paramrefURL parameter name for the referral code.
data-cookie-days90Cookie expiration in days.
data-cookie-domainCurrent domainCookie domain for cross-subdomain tracking.

Example with Custom Options

html
<script
  src="https://scripts.refgrowcdn.com/latest.js"
  data-project-id="YOUR_PROJECT_ID"
  data-param="via"
  data-cookie-days="30"
  data-cookie-domain=".yoursite.com"
  async defer>
</script>

With this configuration, referral links would use ?via=CODE instead of ?ref=CODE, cookies expire after 30 days, and the cookie is shared across all subdomains of yoursite.com.

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 and makes a purchase within 30 days, the affiliate will receive credit for the conversion.

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

If both sites share the same root domain, set the cookie domain to the root:

html
data-cookie-domain=".yoursite.com"

Different domains

For completely different domains, configure your tracking domain in Refgrow project settings. The tracking script will append the referral code as a URL parameter when users navigate between domains.

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*)ref=([^;]*)/
  );
  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('/signup', async (req, res) => {
  const referralCode = req.cookies.ref;

  if (referralCode) {
    // Record attribution via Refgrow API
    await fetch('https://refgrow.com/api/store-attribution', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer rgk_YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        email: req.body.email,
        referral_code: referralCode
      })
    });
  }
});

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 only the referral code and is not used for advertising.

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