ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Business and Employment»
  • E-Commerce & How to Make Money Online

Using CloudFlare to Geotarget Amazon Links

Updated on August 20, 2017
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.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: "https://hubpages.com/privacy-policy#gdpr"

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)