Optimising your ebay affiliate profits


A few months ago I came across phpBay - a Wordpress plugin and API that integrates ebay listings easily into your website. When a user clicks on a product and places a winning bid, you receive a commission from Ebay.

One feature that I found that was missing was being able to show users local auction listings, for example show people from America US listings or people from the England UK listings. However this is now possible to do with my country class, and once installed will enable you to maximise your affiliate profits. To acomplish this you will need to purchase the web lookup service from MaxMind. The class can be downloaded here.

To make this work with wordpress, simply unpack country.php and geo.php, edit the geo.php so that it contains the key that you receive from MaxMind and upload the files to wp-content/plugins/phpBay/ and the phpBay plugin will take care of the rest. This will work on version 3.0 of phpBay

If you need to get this working on a non wordpress site using the API, then you will just need the country.php which contains the country class. To see it working, see my site DVD For A Dollar. Here is how I accomplished the country detection on that site.

At the top of each file I start a session using session_start() so that if a user browses more than one page of a site then it will be able to retreive the country from MaxMind once and then use it on all subsequent pages. Then I use the following code to initiate the class and retreive the country.

PHP:

  1. include( ‘country.php’ );
  2. $ebayCountry = new country();
  3.  
  4. if ( !isset( $_SESSION[‘country’] ) )
  5. {
  6. // replace the ‘x’s on the next line with your MaxMind key
  7. $ebayCountry->licenseKey = "xxxxxxxx";
  8. $ebayCountry->getCountryFromWeb();
  9.  
  10. $_SESSION[‘country’] = $ebayCountry->ISO;
  11. } else
  12. {
  13. $ebayCountry->ISO = $_SESSION[‘country’];
  14. $ebayCountry->setReturnArray();
  15. }

 

Now you can initiate the phpBay class and set the country parameters like this:

PHP:

  1. $ebay = new ebay();
  2.  
  3. $ebay->eb_siteId = $ebayCountry->ReturnArray[ "siteId" ];
  4. $ebay->eb_language = $ebayCountry->ReturnArray[ "language" ];

If you want a combo box that displays a list of countries that defaults to the local ebay like the one on DVD For A Dollar, place the following code above the code that checks if the country session variable has been set:

PHP:

  1. if ( isset( $_POST[‘country’] ) && strlen( $_POST[‘country’] ) == 2 )
  2. $_SESSION[‘country’] = $_POST[‘country’];

Here is the code that draws the combo box itself:

PHP:

  1. function DrawCountryCombo() {
  2. $Countries = array(    "US" => "US Auctions",
  3. "AU" => "Australian Auctions",
  4. "AT" => "Austrian Auctions",
  5. "BE" => "Belgian Auctions",
  6. "CA" => "Canadian Auctions",
  7. "FR" => "French Auctions",
  8. "DE" => "German Auctions",
  9. "HK" => "Hong Kong Auctions",
  10. "IN" => "Indian Auctions",
  11. "IE" => "Irish Auctions",
  12. "IT" => "Italian Auctions",
  13. "NL" => "Dutch Auctions",
  14. "PL" => "Polish Auctions",
  15. "SG" => "Singapore Auctions",
  16. "ES" => "Spanish Auctions",
  17. "CH" => "Swiss Auctions",
  18. "GB" => "UK Auctions"
  19. );
  20.  
  21. $form = ‘<form method="POST" action="">’ . "\r\n";
  22. $form .= ‘<select onchange="javascript:submit();" id="countrycombo" name="country">’ .
  23.  
  24. "\r\n";
  25.  
  26. foreach( $Countries AS $Key => $Value )
  27. {
  28. $form .= ‘<option’;
  29. $form .= ($_SESSION[‘country’] == $Key) ? ‘ selected’ : ;
  30. $form .= ‘ value="’ . $Key . ‘">’ . $Value . ‘</option>’ . "\r\n";
  31. }
  32.  
  33. $form .= ‘</select>’ . "\r\n" . ‘</form>’ . "\r\n";
  34. return $form;
  35. }

To draw the combo box, simply use the following code:

PHP:

  1. echo DrawCountryCombo();

And that’s all there is to adding country detection to your ebay affiliate sites. Huge thanks to Wade who wrote the phpbay class for his support with this project.

If you find this code useful, feel free to buy me a beer.

Site Sponsors

GoDaddy.com $1.99 Domains

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
BrewsterAds
March Malarky

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Hi,
Followed your post from DP thanks for the work on the script. To be honest I find it easier and of course less expensive (no Maxmind fees) to simply put subdomains for each country especially as I am using the Adwords content network, just launching my new site now selling DVD’s to the US, UK and Australia markets. Cool work though Cheers