Affiliates Attribution Setup Guide
The purpose of affiliate attribution is to accurately track and assign rewards to affiliates for the customers or actions (such as sales, subscriptions, or downloads) they bring to a business.
Referral Link Format
All referral URLs generated by SoyCap.io affiliates use the following format:
https://www.cryptowaves.app/landing?sc-ref-id=XXX&sc-cmp-id=YYY
where:
sc-ref-id
is the correspondingreferralId
andsc-cmp-id
is the correspondingcampaignId
To set up affiliate attribution, you’ll need a mechanism to capture, store, and track these parameters through the user journey. Here’s a step-by-step guide to implementing this:
Step 1. Capture Parameters on Page Load
When users arrive on your site (campaign landing page) via an referral link, capture sc-ref-id
(the unique ID assigned to referral link) and sc-cmp-id
(the ID for the specific campaign) from the URL. These values will be used to attribute any subsequent actions (like purchases, conversions or sign-ups) to the affiliate and campaign.
const urlParams = new URLSearchParams(window.location.search);const referralId = urlParams.get('sc-ref-id');const campaignId = urlParams.get('sc-cmp-id');
Step 2. Store Parameters in Cookies or Local Storage
To persist these values as users navigate through your site, store them in cookies or local storage. Cookies are recommended for cross-session tracking, ensuring the referral and campaign IDs remain available even if the user revisits after some time.
if (referralId) { document.cookie = `sc-ref-id=${referralId}; path=/; max-age=2592000`; // 30 days}if (campaignId) { document.cookie = `sc-cmp-id=${campaignId}; path=/; max-age=2592000`;}
Alternatively, you can use local storage for tracking with a 30-day TTL:
function setWithExpiry(key, value, ttl) { const now = new Date(); const item = { value: value, expiry: now.getTime() + ttl, }; localStorage.setItem(key, JSON.stringify(item));}
// Set items with a 30-day TTL (in milliseconds)const ttl = 30 * 24 * 60 * 60 * 1000;if (referralId) { setWithExpiry('sc-ref-id', referralId, ttl);}if (campaignId) { setWithExpiry('sc-cmp-id', campaignId, ttl);}
Step 3. Use Referral Information On Conversion Event
When the user completes a conversion event (e.g., signs up, subscribes, or makes a purchase), get the stored sc-ref-id
and sc-cmp-id
values to create SoyCap.io conversion and distribute affiliate reward.
Getting referral values from cookies:
function getCookie(name) { const cookieString = document.cookie .split('; ') .find(row => row.startsWith(`${name}=`)); return cookieString ? cookieString.split('=')[1] : null;}
const referralId = getCookie('sc-ref-id');const campaignId = getCookie('sc-cmp-id');
console.log('Referral ID:', referralId);console.log('Campaign ID:', campaignId);
Getting referral values from local storage:
function getWithExpiry(key) { const itemStr = localStorage.getItem(key); if (!itemStr) { return null; } const item = JSON.parse(itemStr); const now = new Date(); if (now.getTime() > item.expiry) { localStorage.removeItem(key); return null; } return item.value;}
// Retrieve itemsconst referralId = getWithExpiry('sc-ref-id');const campaignId = getWithExpiry('sc-cmp-id');
console.log('Referral ID:', referralId);console.log('Campaign ID:', campaignId);