Retrieve the referral link for the currently logged-in customer, along with social sharing configuration.
Usage
MageSDK.getReferralLink().then(function(resp) {
if (resp.success && resp.data.enabled) {
console.log('Referral URL:', resp.data.referralUrl);
console.log('Referral code:', resp.data.referralCode);
}
});
Response
Whether the request was successful.
Whether the referral program is enabled for this shop.
The customer’s unique referral code.
Full referral URL that can be shared.
Quick referral statistics.
Total number of people referred.
Number of completed referrals.
Number of pending referrals.
Social sharing configuration set by the merchant.Show Social sharing properties
Whether Twitter/X sharing is enabled.
Pre-filled message for Twitter/X shares.
Whether Facebook sharing is enabled.
Whether email sharing is enabled.
Whether WhatsApp sharing is enabled.
Pre-filled message for WhatsApp shares.
Sample response
{
"success": true,
"data": {
"enabled": true,
"referralCode": "ABC123",
"referralUrl": "https://mystore.com?referral_code=ABC123",
"stats": {
"totalReferred": 5,
"completedReferrals": 2,
"pendingReferrals": 2
},
"socialSharing": {
"twitter": true,
"twitterMessage": "Check out this store!",
"facebook": true,
"email": true,
"whatsapp": true,
"whatsappMessage": "Check out this store!"
}
}
}
<div id="referral-share"></div>
<script>
MageSDK.getReferralLink().then(function(resp) {
if (!resp.success || !resp.data.enabled) return;
var container = document.getElementById('referral-share');
var url = encodeURIComponent(resp.data.referralUrl);
var sharing = resp.data.socialSharing;
if (sharing.twitter) {
var msg = encodeURIComponent(sharing.twitterMessage);
container.innerHTML += '<a href="https://twitter.com/intent/tweet?text=' + msg + '&url=' + url + '" target="_blank">Share on Twitter</a> ';
}
if (sharing.whatsapp) {
var msg = encodeURIComponent(sharing.whatsappMessage + ' ' + resp.data.referralUrl);
container.innerHTML += '<a href="https://wa.me/?text=' + msg + '" target="_blank">Share on WhatsApp</a> ';
}
});
</script>