Affiliates Attribution Setup Guide
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
To set up affiliate attribution where sc-ref-id
is the referralId
and sc-cmp-id
is the campaignId
, 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:
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');
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);}
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);