Refer A Friend JScript API

Written By Devin O'Neill ()

Updated at April 17th, 2025

To Display RAF Sign-up/Landing Page:

This page displays the content for the users to sign up for the Refer a Friend program and start sharing. To configure the RAF landing page, follow the steps below:

  • Create a new landing page with your header and footer.
    E.g. http://www.client-domain/refer-a-friend
  • Add the following <div> within the body of the page to show the Refer a Friend landing/sharing screen.
    <div id="sa_refer_friend"></div>
  • Place the following script before the </body> tag.
<script type="text/javascript">
var sa_uni = sa_uni || [];
sa_uni.push(['sa_pg', '11']);
(function () { function sa_async_load() { var sa = document.createElement('script');
sa.type = 'text/javascript'; sa.async = true;
sa.src = '//cdn.socialannex.com/partner/Enter_siteID/universal.js';
var sax = document.getElementsByTagName('script')[0];
sax.parentNode.insertBefore(sa, sax);
} if (window.attachEvent) {
window.attachEvent('onload', sa_async_load);
} else {
window.addEventListener('load', sa_async_load, false);
}
})();
</script>

Note: In the above code, replace ‘Enter_siteID’ with the siteID provided by Annex Cloud.

To Display the RAF Unlock Coupon Code page:

This page is used to lead all friends back to the client’s website to unlock their discount. There are two separate experiences here on this page depending on if a friend comes back through a referral link or directly to the page. Displaying different experiences within the body of the page will be managed in the end. All other elements on this page will be managed by you.

  1. Create another landing page with your header and footer.
    E.g. http://www.client-domain/friends
  2. Add the following <div> within the body of the page to show the Unlock code screen.
 <div id="socialannex1"></div>
  1. Place the following script before the </body> tag closes.
<script type="text/javascript">
var sa_uni = sa_uni || [];
sa_uni.push(['sa_pg', '12']);
(function () { function sa_async_load() { var sa = document.createElement('script');
sa.type = 'text/javascript'; sa.async = true;
sa.src = '//cdn.socialannex.com/partner/Enter_siteID/universal.js';
var sax = document.getElementsByTagName('script')[0];
sax.parentNode.insertBefore(sa, sax);
} if (window.attachEvent) {
window.attachEvent('onload', sa_async_load);
} else {
window.addEventListener('load', sa_async_load, false);
}
})();
</script>

Note:

  • In the above code, replace ‘Enter_siteID’ with the siteID provided by Annex Cloud.
  • The body of the page contains the Refer a Friend div to display the Refer a Friend unlock coupon code iFrame.
  • The universal.js also needs to be added on this page within the <body> tag for Annex Cloud to power the RAF content.
  • If you are managing the RAF UI/UX, then you will need to use our RAF (Refer a Friend) APIs to manage sharing and referrals.

Add Sales Tracking Pixel On Order Confirmation Page:

  • Add the following Sales Track Pixel on the order confirmation page.
<script src="https://c1.socialannex.com/sale-track/?parameter=<ENCODE base64 String>"></script>

The following parameters are needed for creating the JSON string:

  • ORDER_ID: Pass the user’s order id.
  • SALE_AMOUNT: Pass the total sale amount for the order placed by the users. The total amount should be without a currency symbol. E.g. If the total sales amount is $78.31, then pass 78.31 only.
  • EMAIL: Pass the user’s email address.
  • FULL NAME: Pass the name of the user.
  • couponDetails: Pass the coupon code(s) used by the user. The following are examples of passing coupon codes.
$couponDetails = array("CodeA","CodeB"); //For Multiple Coupons
$couponDetails = "CodeA"; //For Single Coupon
$couponDetails = ""; //For No Coupon

excludeProductArray: Create an array for the product's information as shown in the following example.

Eg:
$excludeProductArray = array("1"=>array("product_url"=>"https://www.abc.com/3PW145560X.html",
"category_name"=>"Default",
"category_id"=>"cat10001",
"price"=>"25.95",
"qty"=>"1",
"id"=>"44251",
"product_image_url"=>"https://www.abc.com/mm5/graphics/00000001/3PW145560X.jpg",
"product_name"=>"Test Product"),
"2"=>array("product_url"=>"https://www.xyz.com/3PW145560X.html",
"category_name"=>"Default",
"category_id"=>"cat10001",
"price"=>"25.95",
"qty"=>"1",
"id"=>"44251",
"product_image_url"=>"https://www.xyz.com/mm5/graphics/00000001/3PW145560X.jpg",
"product_name"=>"Test Product"));
Create the array using the above parameters and convert it into JSON string as shown below.
$options = array("site_id"=>"Enter_Site_ID",
        "order_id"=>"ORDER_ID",
        "sale_amount"=>"SALE_AMOUNT",
        "email_id"=>"EMAIL",
        "name"=>"FULLNAME",
        "coupon"=>$couponDetails,
        "exclude_products"=>$excludeProductArray); 

In the above code, replace ENTER_SITE_ID with the site id provided by Annex Cloud.

  • Convert the above JSON string into base64 format as shown below and pass it into the API.
$encodedParameter = base64_encode(json_encode($options));

Sample Example:
$excludeProductArray = array("1"=>array("product_url"=>"https://www.abc.com/3PW145560X.html",
"category_name"=>"Default",
"category_id"=>"cat10001",
"price"=>"25.95",
"qty"=>"1",
"id"=>"44251",
"product_image_url"=>"https://www.abc.com/mm5/graphics/00000001/3PW145560X.jpg",
"product_name"=>"Test Product"),
"2"=>array("product_url"=>"https://www.xyz.com/3PW145560X.html",
"category_name"=>"Default",
"category_id"=>"cat10001",
"price"=>"25.95",
"qty"=>"1",
"id"=>"44251",
"product_image_url"=>"https://www.xyz.com/mm5/graphics/00000001/3PW145560X.jpg",
"product_name"=>"Test Product"));
$couponDetails =  array("CodeA","CodeB"); //For Multiple Coupons
$options = array("site_id"=>"Enter_Site_ID", 
                "order_id"=>"ORDER_ID", 
                "sale_amount"=>"SALE_AMOUNT", 
                "email_id"=>"EMAIL",
                "name"=>"FULLNAME",
                "coupon"=>$couponDetails,
                "exclude_products"=>$excludeProductArray);
$encodedParameter = base64_encode(json_encode($options));
<script src="https://c1.socialannex.com/sale-track/?parameter=<?php
echo $encodedParameter;?>"></script>