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');
// 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.
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.
| Attribute | Default | Description |
|---|---|---|
data-project-id | — | Required. Your Refgrow project ID. |
Script Tag
<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:
- 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, 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:
- 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*)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:
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:
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
- Stripe Integration — set up automatic commission tracking with Stripe
- Widget Customization — embed the affiliate dashboard
- API Reference — learn about programmatic conversion tracking