Sponsored Links

Use your affiliate program to increase search engine rankings

Do you sell a product on the web and have an affiliate program for it? If so, you may not be getting the most out of your affiliate program.

How do affiliate programs work?

Your affiliates drive traffic to their sites. They put a review of your product and then link to your site using a special affiliate link. Examples would be: www.yourdomain.com/?affiliate_id=12 or www.affiliateprogramprovider.com/ ?product_id=43&affiliate_id=12451

When a visitor clicks that link, a script at your site or your affiliate program provider places a cookie on the visitor's computer and if that visitor buys now or later, your affiliate gets a commission. It works great but what if your affiliates could simply put a plain link to your site and still get a commission for any resulting sales?

It works like this. Instead of using long affiliate URLs, your affiliates put a plain link to your site. When someone clicks that link and comes to your site, a script at your site finds out that the visitor comes from an affiliate site. That script places a cookie on the visitor's computer and saves its IP address. The IP address is saved because some surfers erase their cookies. Later the script can identify that user by both a cookie or the IP address.

If later that visitor decides to buy, the script at your order page or the page leading to your order page puts the affiliate ID in the final order URL. Your affiliates get their commission.

This technique has a huge advantage!

  1. You get link popularity from your affiliates because they put plain links! That means increased search engine positions.
  2. The visitors of your affiliate website will not know the link is affiliated! They won't know that the owner gets a commission and that increases the credibility of the product recommendation. Better credibility = better conversions = more sales.

There are two drawbacks:

  1. you'll need a script to do the job
  2. some users disable referer logging - that means their browsers won't tell you which page they came from and the script won't be able to identify them as coming from your affiliate site. In my experience, 1. the number of such users is small 2. they tend to not buy from affiliate links 3. the convertion rate of a plain link will outproduce vastly an affiliate link

In this article, I will show you a very simple way to do it in php and mysql. If you have basic php/mysql knowledge, you will be able to modify it to your needs, or you can hire a developer to do that for you.

The files

affsetup.php - that file contains the database connection information and the cookie parameters. It will be included on the pages that include the affiliate tracking script.


<?php
$dbhost = 'localhost';
$dbname = 'database name goes here';
$dbuser = 'database user name goes here';
$dbpass = 'database user password';

$cookiedomain = '';
$cookiename = 'affscript'; //the cookie name
$cookiepath = '';
$cookiesecure = FALSE;
?>

affinstall.php - this file will create the data tables. Run it once and after that delete it from your web server.
<?php
require ('affsetup.php'); // include the database/cookie settings

@mysql_connect($dbhost, $dbuser, $dbpass) or die ('Database Error');
@mysql_select_db($dbname) or die ('Database Error');


$q[] = "DROP TABLE IF EXISTS aff";
$q[] = "CREATE TABLE aff (
aff_id int(10) unsigned NOT NULL DEFAULT '0', #affiliate id identifying the affiliate
aff_url char(255) NOT NULL DEFAULT '', #affiliate site URL example: affiliatedomain.com
PRIMARY KEY (aff_id)
) TYPE=MyISAM;";

$q[] = "DROP TABLE IF EXISTS customers";
$q[] = "CREATE TABLE customers (
customer_ip varchar(15) NOT NULL default 'Unknown',
customer_time int(10) unsigned NOT NULL DEFAULT '0',
aff_id int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (customer_ip)
) TYPE=MyISAM;";

foreach ($q as $query)
{
   mysql_query($query) or die (mysql_error());
}

?>

Each row in the aff table will contain a pair of affiliate ID and the affiliate domain name. Some affiliates may promote your product on more than one site and each of their sites will be added in a separate row.

The affiliate url will be kept without the www. and won't be a specific page but a whole domain. Example: if you put affdomain.com, the script will later recognize links from all pages placed on www.affdomain.com as affiliated (example: www.affdomain.com/page1.htm , affdomain.com/page2.htm etc). If that affdomain has subdomains, you'll need to place every subdomain in the database (example: subdomain.affdomain.com)

When an affiliate signs up with your affiliate program, he/she will be assigned an affiliate ID. Then that affiliate will need to email you all of his/her sites and you will add them to the aff table.

Example: an affiliate signs up and has an affiliate ID of 11032. Later he emails you his two sites: www.affsite1.com and www.affsite2.com You will need to add 2 rows to the aff table. Both rows with aff_id of 11032 and the aff_url will be affsite1.com and affsite2.com (without the www. and also lower cased)

Next you'll need to place the affiliate recognition script on your landing pages. Because you will send out cookies, the script will be placed at the top of the files before sending out any HTML (cookies are sent with the HTML headers before any HTML!). If your landing pages have a .htm or .html extension, you will have to tell Apache to run them as php scripts. To allow .htm files to be run as php scripts put this line in your .htaccess file:
AddType application/x-httpd-php .php .htm

Here's the php snippet I use to identify visitors coming from affiliate sites. Put that on top of your HTML landing files.


<?php
function array_add_slashes(&$array)
{
foreach($array as $var => $val)
    {
       if (is_array($val))
       {
          array_add_slashes($array[$var]);
       }
       else
       {
          $array[$var] = addslashes($array[$var]);
       }
    }
}
error_reporting(0);
set_magic_quotes_runtime(0);
if (!get_magic_quotes_gpc())
{ // I use this convention on all my scripts to ensure every variable is addslahed :
    array_add_slashes($_GET);
    array_add_slashes($_POST);
    array_add_slashes($_COOKIE);
}
include('affsetup.php');
if (isset($_SERVER["HTTP_REFERER"])) //is the referer var set?
{
    $r = strtolower($_SERVER["HTTP_REFERER"]); //make it lower case
    $r = str_replace('https://', 'http://', $r); //replace https:// with http://
    $r = str_replace('http://www.', '', $r); // delete the leading www.
    $pos = strpos($r, 'http://');

    $i = ($pos === false) ? 0 : 2;

    $s = explode('/', $r);
    $u = $s[$i]; // $u now contains the domain name of the referer
    @mysql_connect($dbhost, $dbuser, $dbpass);
    @mysql_select_db($dbname);
    $u = addslashes($u);
    $result = @mysql_query("SELECT aff_id FROM aff WHERE aff_url='$u'");
    if (isset($_COOKIE[$cookiename]))
    {//if that visitor has come from an affiliate site before, then do nothing
    //that will favor the first affiliate referrer; if you want you can change that.
    }
    else
    if (@mysql_num_rows($result) == 1)
    {
       $aff_id = @mysql_result($result, 0);
       $c_ip = $_SERVER["REMOTE_ADDR"];
       $c_time = time();
       @mysql_query("REPLACE INTO customers (customer_ip, customer_time, aff_id) VALUES ('$c_ip','$c_time','$aff_id')"); // add visitor to the database and
       @setcookie($cookiename, serialize($aff_id), time() + 31536000, $cookiepath, $cookiedomain, $cookiesecure); //set a cookie on his/her computer
    }
}
?>

Finally, on the page that leads to your order URL, you will need to identify the visitors coming from affiliate sites (cookie and IP address) and add the affiliate ID to the final order URL. My assumption is that you have an order page on your website that will link to the final order page that's on your credit card provider. Put that code at the top of the order page that will lead to the final secure order page:


<?php
function array_add_slashes(&$array)
{
    foreach($array as $var => $val)
    {
       if (is_array($val))
       {
          array_add_slashes($array[$var]);
       }
       else
       {
          $array[$var] = addslashes($array[$var]);
       }
    }
}
error_reporting(0);
set_magic_quotes_runtime(0);
if (!get_magic_quotes_gpc())
{
    array_add_slashes($_GET);
    array_add_slashes($_POST);
    array_add_slashes($_COOKIE);
}
include('affsetup.php');
$aff_id=null;
if (isset($_COOKIE[$cookiename]))
{
    $aff_id = @unserialize(stripslashes($_COOKIE[$cookiename]));
}
else
{
    @mysql_connect($dbhost, $dbuser, $dbpass);
    @mysql_select_db($dbname);
    $c_ip = $_SERVER["REMOTE_ADDR"];
    $result = @mysql_query("SELECT aff_id FROM customers WHERE customer_ip='$c_ip'");
    if (@mysql_num_rows($result) != 0)
       $aff_id = @mysql_result($result, 0);
}
if (!is_null($aff_id))
{
    //here $aff_id contains the affiliate ID, generate an affiliate order URL
}
else
{
    //the order is not from a visitor coming from an affiliate site, generate a normal order URL
}

?>

This example script is very simple and you'll need to modify it to suit your needs. I do database administration (adding affiliates) through the phpmyadmin (provided by most hosting companies).

Other variants:
- instead of placing a cookie when a user comes from an affiliate site, you can redirect them to the affiliate URL, which will place a cookie and then redirect to the very same page. That has the disadvantage of not tracking the IP address (unless your affiliate program provider does that).

Additional tips:

  1. Bribe your affiliates. Set a higher commission percentage to the ones who give you higher PageRank links.
  2. Tell your affiliates not to copy your sales letter. Copying your page means duplicate content and their page won't be able to drive search engine traffic because of that. Search engines will detect the duplicate content and filter out their page because yours is older/more established.
  3. Email your affiliates who don't take advantage of the plain linking script and explain them the benefits.

A final tip. An affiliate can earn commission without having a website! It can be done through forum signatures. Example: you have a webmaster related product. An affiliate signs up. That affiliate posts on webmaster forums using a plain link to your product. Whenever someone clicks his signature link and later buys, the affiliate collects the commission.

Good luck with your affiliate program. If you need help with the script, ask me on the forums.

Latest SEO Blog Entries

Shareware Marketing 101 - 28 August 2006
Google Webmaster Central To Solve Canonical Issues - 16 August 2006
Forum Upgraded With Signatures and Avatars - 13 July 2006
Climbing the Keyword Ladder - 17 June 2006
PayPal Is Not Enough - 12 June 2006
SEO Guide Gets a New White-Grey-Black Hat Skin - 06 June 2006
Matt Cutts On BigDaddy, PageRank and The SandBox - 17 May 2006
Google Patents On PageRank Variants - 11 April 2006
Microsoft Paper Gives Clues Into The Future of SEO - 10 April 2006
Focus On The User And Get More Traffic And Revenue - 09 March 2006