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:
<!-- 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
// 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:
| Attribute | Default | Description |
|---|---|---|
data-project-id | — | Required. Your Refgrow project ID. |
data-param | ref | URL parameter name for the referral code. |
data-cookie-days | 90 | Cookie expiration in days. |
data-cookie-domain | Current domain | Cookie domain for cross-subdomain tracking. |
Example with Custom Options
<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:
- Go to your project settings
- Click "Create Stripe API Key" button or enter your existing key
- The system will automatically configure webhooks and start tracking your Stripe payments
LemonSqueezy Webhook Setup
- Go to your LemonSqueezy Dashboard → Settings → Webhooks
- Click "Add webhook"
- Set the webhook URL to:
https://refgrow.com/webhook/lemonsqueezy/YOUR_PROJECT_ID - Replace YOUR_PROJECT_ID with your actual project ID
- Select the following events:
order_createdsubscription_createdsubscription_updated
- Click "Create webhook" to save
Cookie Lifetime Configuration
You can configure how long the referral tracking cookie lasts in your project settings:
- Go to your project settings
- Find the "Cookie Lifetime" setting
- Set the number of days you want the tracking cookie to last
- 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:
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:
- Go to your project settings
- Find the "Tracking Domain" setting
- Enter your domain (e.g., yourdomain.com)
- 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 (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:
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:
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
- Stripe Integration — set up automatic commission tracking with Stripe
- Widget Customization — embed the affiliate dashboard
- API Reference — learn about programmatic conversion tracking