Attribution Script
Install the RefRef attribution script to track referrals
Overview
The RefRef attribution script is a lightweight JavaScript library that automatically tracks referral codes from URL parameters, stores them in cookies, and populates form fields. This enables accurate attribution of referrals to the right participants.
How It Works
- User clicks a referral link (e.g.,
yoursite.com?refcode=abc1234) - Attribution script detects the
refcodeURL parameter - Refcode is stored in a cookie (
refref-refcode) for 90 days - When the user signs up, the refcode is automatically populated in your form
- Your backend receives the refcode with the signup request
- You pass the refcode when creating events via the RefRef API
- RefRef creates the referral connection and generates rewards
Installation
Step 1: Add the Script Tag
Add the attribution script to your website's <head> tag or before the closing </body> tag:
The defer attribute ensures the script runs after the page loads without blocking rendering.
Step 2: Add Hidden Form Field
Add a hidden input field to your signup form with the data-refref attribute:
The attribution script automatically finds all elements with data-refref="refcode" and populates them with the stored refcode.
Step 3: Capture Refcode in Your Backend
When processing signups, capture the refcode from the form submission:
Step 4: Fire Events with Refcode
When a qualifying event occurs (signup, purchase, etc.), include the refcode in your event creation:
Configuration Options
The attribution script can be configured via data attributes or JavaScript:
Testing Attribution
Verify Script is Loaded
Open your browser's developer console and check for the RefRef script:
Test with a Sample Refcode
- Visit your site with a refcode parameter:
https://yoursite.com?refcode=test123 - Open browser DevTools → Application → Cookies
- Look for a cookie named
refref-refcodewith valuetest123 - Navigate to your signup page
- Inspect the hidden form field - it should contain
test123