ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Using CloudFlare to Geotarget Amazon Links

Updated on October 2, 2014
Geotargeting affiliate links can help you earn more from international traffic.
Geotargeting affiliate links can help you earn more from international traffic.

You will need:

  • A website using CloudFlare, with IP Geolocation enabled
  • Accounts with Amazon Associates sites of different countries
  • Minimal PHP knowledge

Amazon Associates is an excellent affiliate program, but if your website receives a lot of visitors from outside the US, one problem becomes quickly apparent. Not only Amazon's Canadian and European sites each have their own affiliate programs, there's no built-in way to redirect your foreign visitor to the appropriate online store. To maximize your earnings potential, you have to turn to third-party tools, or use a makeshift solution such as the one I came up with, which utilizes CloudFlare's free IP Geolocation.

CloudFlare is a great service which makes your website faster and more secure, and provides a plethora of other useful features. Some of these are only available with paid plans; however, the aforementioned IP Geolocation is accessible to all members. This opens up the possibility of using it to geotarget your Amazon Associates or other links. Admittedly, this requires some work to set up, and isn't as convenient as so-called "globalizer" plugins. On the bright side, this method isn't going to cost you anything, and 100% of your Amazon clicks will be credited to you (whereas globalizers usually take a few percent of your clicks as a payment for their services).

My little guide assumes that you are already using CloudFlare; if you need help setting it up, try their support section instead.

Step 1: Enable IP Geolocation

You will find this in the CloudFlare settings for your site - simply turn it on.
You will find this in the CloudFlare settings for your site - simply turn it on.

Step 2: Create the PHP File(s) for Geotargeted Redirection

All you have to do is grab the "CF_IPCountry" header which CloudFlare now adds to every request, and use it send your visitor to the Amazon store of his home country using PHP. The file can be named "yourproduct.php", "index.php" (if placed in a directory of its own), or whatever else you prefer.

There are several different ways you can go about it, such as simply creating a new PHP file for each product, or passing the ASIN or the keywords as variables via the URL. The first method is less complicated in terms of programming and more accurate (since not every Amazon store will have the same product or use the same ASIN for it), but the second one more convenient and less time-consuming. I'll cover them both and provide sample code that you'll be able to copy over to your webhost and use it after adding your own Amazon Associates products and tags.

Basic approach: a new file for each product

Create a new .php file for each product that you want to link to, and paste in the code shown below. Grab your affiliate links from all international Amazon sites that it is available at, and replace my placeholder links (the ones after the "location:" part) with actual ones. Then, instead of linking from your blog to Amazon directly, link to your modified .php file, and you're good to go!

<?php
$country = $_SERVER["HTTP_CF_IPCOUNTRY"];
if ($country == "UK" || $country == "GB") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.co.uk/dp/YOURASIN/?tag=yourtag');
exit;
}
elseif ($country == "DE") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.de/dp/YOURASIN/?tag=yourtag');
exit;
}
elseif ($country == "FR") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.fr/dp/YOURASIN/?tag=yourtag');
exit;
}
else {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.com/dp/YOURASIN/?tag=yourtag');
exit;
}
?>

I used UK, German, and French sites in the example below - everyone else (including American visitors) will get sent to the Amazon.com site. You can easily add other Amazon stores, such as Italian or Spanish, by duplicating one of the "elseif" paragraphs and replacing the country code with IT or ES.

Advanced approach: using keywords

You can eliminate the need to create a new file for each product by using keywords and sending your visitors to the search results. Unfortunately, these don't look as good as individual product pages, but it's a huge time saver if you have a lot of products to link to. Use the following code, and don't forget to replace the placeholder Associates tags with your own.

<?php
$product = urlencode($_GET['product']);
$country = $_SERVER["HTTP_CF_IPCOUNTRY"];
	if ($country == "UK" || $country == "GB") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.co.uk/s/?tag=YOURTAG&keywords=' . $product);
exit;
	}
	elseif ($country == "DE") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.de/s/?tag=YOURTAG&keywords=' . $product);
exit;
	}
	elseif ($country == "FR") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.fr/s/?tag=YOURTAG&keywords=' . $product);
exit;
	}
	else {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.com/s/?tag=YOURTAG&keywords=' . $product);
exit;
	}
?>

Provided you named your file "amazon.php", you can link to it in the following way, replacing the part in bold with your own search keywords separated by a plus sign:

http://yourdomain.com/amazon.php?product=Cool+Item

Advanced approach: using the ASIN

This method seems perfect at first: by using the ASIN, you can link to product pages instead of search results, and you still only need a single .php file. Unfortunately, only some products which are sold by Amazon directly have the same ASIN across all their sites. Products from Amazon Sellers usually have unique ASINs, and you will get an error if you try to use it on another site, thus doing more harm than good. As such, I don't really recommend using this method, unless you are prepared to check every single ASIN manually to ensure it matches the same product on every site (which is a rare occurrence).

<?php
$asin = urlencode($_GET['asin']);
$country = $_SERVER["HTTP_CF_IPCOUNTRY"];
	if ($country == "UK" || $country == "GB") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.co.uk/dp/'. $asin .'/?tag=YOURTAG);
exit;
	}
	elseif ($country == "DE") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.de/dp/'. $asin .'/?tag=YOURTAG);
exit;
	}
	elseif ($country == "FR") {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.fr/dp/'. $asin .'/?tag=YOURTAG);
exit;
	}
	else {
header('HTTP/1.1 301 Moved Permanently');
header ('location: http://www.amazon.com/dp/'. $asin .'/?tag=YOURTAG);
exit;
	}
?>

While I don't recommend this approach, if you do decide to use it, you can pass on the variable as follows (replacing the part in bold with your own ASIN):

http://yourdomain.com/amazon.php?asin=B004FEEY9A

Important Notice

There are two more things that you have to know before using the technique I described above to geotarget your affiliate links. First of all, while doing this isn't against Amazon's Terms of Service (the 301 redirect passes the HTTP referer, so the origin of the clicks isn't hidden, which makes it OK), you can't "trick" your visitors into thinking the link leads somewhere else. You have to label every link to make it clear that it goes to Amazon. This won't be apparent just from the link itself, since it will now lead to your .php file instead of Amazon's website.

The second point is related to Google and other robots. The big G recommends using rel="nofollow" or robots.txt for paid and affiliate links, so that's what you should do. The second way is definitely easier than adding rel="nofollow" to every Amazon link. Simply place your "amazon.php" file into a separate directory, and then use robots.txt to block said directory from all search engine spiders. Google themselves mention this method as a valid way of dealing with sponsored links in their webmaster guidelines:

Redirecting the links to an intermediate page that is blocked from search engines with a robots.txt file

So, there you have it - a relatively easy and completely free way to geotarget your Amazon links using CloudFlare. If you encounter any issues with the code provided, feel free to ask for help in the comments below.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    Click to Rate This Article