Integrating Affiliate Program

Knowledgebase Articles: Integrating Affiliate Program

Please use the following instructions to integrate a third party affiliate network (e.g. Linkshare) with your site:

1. Go to Manage Website->Edit Website section
2. Select Home->Shopping Cart->Order Confirmation page from Website Map
3. Click on Edit Page tab
4. Drag and drop HTML section into the middle container after Order Confirmation page section. It is important that HTML section is added after Order Confirmation section.
5. Open section editor for HTML section by clicking on pencil icon.
6. Copy/Paste JavaScript snippet for getting order values  into the Editor.

// Snippet 1

<script type="text/javascript">

if (document.getElementById){
 var orderId = document.getElementById("orderId");
 if ( orderId != null){
 // orderId
 orderId  = orderId.value;

 // order total
 var orderTotal  = document.getElementById("orderTotal").value;

 // order product subtotal
 var orderSubtotal = document.getElementById("orderSubtotal").value;

 // product subtotal without taxes and with discount applied 
 var netOrderSubtotal = document.getElementById("netOrderSubtotal").value;

 // order discount Total
 var discountTotal = document.getElementById("discountTotal").value;

 // order shipping cost
 var shippingCost  = document.getElementById("shippingCost").value;

 // order currency (3 letter ISO currency code e.g. GBP)
 var currencyCode  = document.getElementById("currencyCode").value;

 //  integration code here using orderId, orderSubtotal, etc values 
//  e.g. document.write();
  
  }
  else{
 // control panel preview mode
  }
}
else{
// older browsers
}
 
</script>

//Snippet 2

<!-- Code for Linkshare Banner Advertising Commission Tracking-->

<script type="text/javascript">

    var productLinkPrefix = '/product/';

    if (document.getElementById)
    {
        var orderId = document.getElementById("orderId");
        if (orderId != null)
        {
            // orderId
            orderId = orderId.value;
            // order currency (3 letter ISO currency code e.g. GBP)
            var currencyCode = document.getElementById("currencyCode").value;

            var skuList = '';
            var qlist = '';
            var amtList = '';

            var table;
            if (document.getElementsByClassName)
            {
                table = document.getElementsByClassName("base")[2];
            }
            else
            {
                // Try to find via jquery
                table = $(".base")[2];                
            }
                
            if (table != null && table != undefined)
            {
                var rows = table.rows;

                if (rows != undefined)
                {
                    var tableHeaders = rows[0];
                    var tableWithoutSku = (tableHeaders.cells.length == 4);
                    
                    var qtyIndex = 3;
                    var amtIndex = 4;
                    
                    if (tableWithoutSku)
                    {
                        qtyIndex = 2;
                        amtIndex = 3;
                    }
                    
                    for (var i = 1; i < rows.length; i++)
                    {
                        var row = rows[i];
                        var cells = row.cells;
                        
                        if (row.className == 'nameOption' && cells.length == 2)
                        {
                            // Row represents a product option, skip it
                            continue;
                        }
                        
                        // add separator between values of the lists
                        if (i > 1)
                        {
                            skuList += ',';
                            qlist += ',';
                            amtList += ','
                        }

                        // add item sku to the sku list
                        var cellWithLinkToProduct = cells[0];
                        var linkToProductList = cellWithLinkToProduct.getElementsByTagName('a');
                        
                        if (linkToProductList.length == 1)
                        {
                            var linkToProduct = linkToProductList[0];
                            var href = linkToProduct.href;
                            // href contains sku 
                            // href has the following format '*/product/SKU/productName'
                            // extract sku
                            var pos = href.indexOf(productLinkPrefix);
                            if (pos >=0)
                            {
                                href = href.substring(pos + productLinkPrefix.length);
                                pos = href.indexOf('/');
                                if (pos >= 0)
                                {
                                    var sku = href.substring(0, pos);
                                    skuList += sku;
                                }
                            }
                        }
                       
                        //add item quantity to the quantity list
                        var qty = cells[qtyIndex].innerHTML;
                        if (qty != undefined && qty != '')
                        {
                            qlist += qty;
                        }

                        //add item amount to the amount list
                        var amt = cells[amtIndex].innerHTML;
                        if (amt != undefined && amt != '')
                        {
                            var amtValue = amt.substring(1);
                            amtValue = parseInt(amtValue * 100);
                            amtList += amtValue;
                        }
                    }
                }
            }

            // %MerchantID% - Merhcant ID provided by LinkShare

            document.write('<img src="http://track.linksynergy.com/ep?mid=%MerchantID%&ord=' + orderId + '&skulist=' + skuList + '&qlist=' + qlist + '&amtlist=' + amtList + '&cur=' + currencyCode + '">');
        }
        else
        {
            // control panel preview mode
        }
    }
    else
    {
        // older browsers
    }
</script>

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.