Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryMarketing With Software

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Better Links for Affiliates

An affiliate link has two strikes against it.

  1. The hardest strike to overcome is the way the link URL looks.

    Many affiliate links have little indication within the URL itself about what the destination page will contain.

    The URL can look suspicious causing people to avoid tapping it. Some people, many people, have internalized a self-directive that they should never tap a suspicious looking link or URL.

  2. There are people who won't tap a link that looks like an affiliate link. I don't understand the mindset, but it is a real thing.

Some countries, perhaps most, have laws related to being transparent about affiliate links. "Hey, I get rewarded if you buy this book!" may be sufficient in some cases. If it's an ad, then the fact of being an ad may be sufficient disclosure.

Whatever the legal requirements are, I want to be clear that the software provided in this article is not in any way intended to bypass them.

Instead, I'm providing the means to use a link URL that more fully discloses what awaits them when the person taps on the link.

To that end, which of these two link URLs is the best statement about the content the link leads to?

https://www.smashwords.com/books/view/1008389?ref=AffCode
https://willbontrager.com/book/AffCode/AmishRecipes/Chocolate-Covered-Candy

Which is the most transparent and best discloses the purpose of the link?

In my opinion, the second version is much desired over the first one.

The software in this article is for affiliates who want their affiliate links to be more real — have better disclosure about the content the person will find when they click on it.

It can be used in various ways.

  • For your own affiliate links.

    Affiliate links with better disclosure can be to your own website. This software logs the click and sends the browser to your real affiliate link.

  • If you are a merchant who administers their own affiliate program.

    Affiliate links can be made with better disclosure than affiliate software generally provides for.

  • To assist affiliates who link to your products at a distributor or retailer.

    Smashwords is both a distributor and retailer of the Amish Recipes: Chocolate-Covered Candy book. Smashwords has an affiliate program.

    The two example links further above are templates for Smashwords affiliates who advertise the Amish Recipes: Chocolate-Covered Candy book. (Affiliates replace AffCode with their own affiliate code.)

The log does not record sales. That particular statistic is the realm of the affiliate software of the website that makes the sales.

If you are a merchant and provide these affiliate links to others, whether you run your own affilate program or you assist affiliates of a distributor or retailer, it may be prudent to make restricted access to the log available for affiliates to see statistics related to their link activity. This is what WillBontrager.com does.

Implementing the Better Links for Affiliates Functionality

Implementation requires 3 steps.

  1. Install Affiliate Link Handler, a PHP script.

  2. Create a subdirectory for use only by the Better Links for Affiliates functionality and give it a .htaccess file.

  3. Create one or more affiliate links to use the functionality.

Installing the Affiliate Link Handler script.

The source code of the Affiliate Link Handler PHP script is below. Notes follow.

<?php
/*
Affiliate Link Handler
(basic affiliate redirect with logging)
Version 1.0;
March 23, 2010
Will Bontrager Software LLC
https://www.willmaster.com/
*/

/* Two Customizations */
// Place 1 --
// Specify the redirect destination URL. 
//   Use {AFFCODE} where the affiliate code 
//   shall be inserted.

$Destination = "https://www.smashwords.com/books/view/1008389?ref={AFFCODE}";

// Place 2 --
// Specify the location of the log file. 
//   If applicable, use {AFFCODE} where 
//   the affiliate code shall be inserted.

$LogFile = "./book/Aff_{AFFCODE}_Log.csv";

/* End of customizations */

if( empty($_GET['_book']) ) { SendBrowserTo( preg_replace('/\?.*$/','',$Destination) ); }
$matches = array();
preg_match('!^([^/]+)!',$_GET['_book'],$matches);
$affcode = (count($matches)>1) ? $matches[1] : '';
$LogData = array();
$LogData[] = time();
$LogData[] = $_SERVER['REMOTE_ADDR'];
$LogData[] = str_replace('"','""',$affcode);
$LogData[] = str_replace('"','""',$_SERVER['REQUEST_URI']);
$LogData[] = str_replace('"','""',$_SERVER['HTTP_USER_AGENT']);
file_put_contents( str_replace('{AFFCODE}',$affcode,$LogFile), '"'.implode('","',$LogData)."\"\n",FILE_APPEND);
SendBrowserTo( str_replace('{AFFCODE}',$affcode,$Destination) );

function SendBrowserTo($url)
{
   $url = trim($url);
   if( headers_sent() ) { echo "<script>location.href='$url'</script>"; }
   else { header("Location: $url"); }
   exit;
}
?>

Customizations —

There are two places to customize.

  1. Replace:

    https://www.smashwords.com/books/view/1008389?ref={AFFCODE}
    

    With the affiliate URL to your product.

    Either

    • Put the placeholder {AFFCODE} where the affiliate code goes in the URL.

    Or

    • If the system will always work with the same affiliate code then, optionally, the affiliate code may be put into the URL where it belongs in lieu of the {AFFCODE} placeholder.

  2. Replace:

    ./book/Aff_{AFFCODE}_Log.csv
    

    With the affiliate location of the log file to update when the affiliate link URL is used. The location may be relative (begins with any directory character other than a "/") or it may be specific (begins with a "/" character or with $_SERVER['DOCUMENT_ROOT']).

    The log file name may be whatever works for you. If you put the {AFFCODE} placeholder into the log file name, then a separate log file will be maintained for each affiliate code.

    The log file content will be CSV formatted. Thus, it is prudent to give the log file name the .csv file name extension.

Save the Affiliate Link Handler script as afflink.php or other .php file name that you prefer.

Upload afflink.php to your server in a location accessible by browsers.

Subdirectory and .htaccess File for Better Links for Affiliates Functionality

Create a subdirectory dedicated to the Better Links for Affiliates functionality.

The subdirectory will contain a .htaccess file. Nothing else will be accessible in the directory using browsers or bots.

Here is the .htaccess file. Notes follow.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /afflink.php?_book=$1&_ref=%{HTTP_REFERER}&%{QUERY_STRING} [L]

Customization —

The above code assumes you placed afflink.php in your document root directory.

If the Affiliate Link Handler script file name is different or in a different directory, then replace /afflink.php with the correct location of the script.

Affiliate Links

In addition to being informative for the person tapping on the link, the link URL can be used to record campaign and source information in the log. This section describes how to accomplish both.

In all examples, AffCode is to be replaced with a valid affiliate code for live links. Testing can be done with AffCode left in the link.

Let's have a look at this example link. It can serve as a template to build your own links.

https://willbontrager.com/book/AffCode/AmishRecipes/Chocolate-Covered-Candy

Here is what the various colored sections of the link URL represent.

  • https://willbontrager.com/book/

    This first part of the link URL is the URL to the subdirectory created for the .htaccess file in a previous step. Replace the red part with your URL.

  • AffCode

    Replace AffCode with the affiliate's affiliate code.

  • /AmishRecipes/Chocolate-Covered-Candy

    All of the green part is optional. You may remove it or replace it with any valid URL characters — so long as the first character is a slash ("/" character). The green part can be used to:

    • Embed product name or other information to assist the person who taps the link.

    • Embed campaign, source, or other information so it ends up in the link click logs.

    The product name itself can be arranged in ways that allow you to keep track of where the link was clicked. Below are examples. Notes can be maintained in a separate text file so each variation can be used as an indication of which link or ad was clicked:

    /AmishRecipes/Chocolate-Covered-Candy /AmishRecipes/Chocolate-Covered/Candy /AmishRecipes_Chocolate-Covered-Candy /AmishRecipesChocolateCoveredCandy /Yummy-Candy-Recipes /special/Will's_Book

    Each of those are different, yet provide information to the person about to tap the link.

    To create a link URL, replace the green part with information for the person who taps on the link. The information may contain campaign or link source data.

    Remember, the first character of the green part, if you use it, must be a slash ("/") character.

At this point, your Better Links for Affiliates functionality is ready to go.

Test affiliate links you create to verify they work as intended. It generally is prudent to check every new affiliate link, especially when they are created manually, to ensure no typed or pasted mistake invalidates the link URL.

(This article first appeared with an issue of the Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC