GeoTargetting with Maxmind and PHP

in php

GeoTargetting, or being able to tell the country/city/state of your visitor, is applicable to most verticles but, in the gambling industry, there are situations where it becomes especially key in improving conversions. Some rooms do not accept US players, some rooms do. By combining this useful script and the API from Maxmind, you can create pages that not only convert better but also provide a more positive experience for your user.

I created this guide as an easy get started method for geotargetting with maxmind’s geolocation db. In this example we will be using the API provided to avoid having to setup a database and for simplicity of use.

Disclaimer: I say that this is “easy” but it may not be “simple”. If you follow the step by step instructions you will be able to effectively use this script.

What You Will Need to Know BEFORE You Get Started

  • How to access your site via FTP
  • The ABSOLUTE PATH to your server – This is NOT www.whateverdomain.com, this looks like /home/public_html/mb/inc. If you do not know this path, you can ask your hosting company or search their website for the phrase “What is the absolute path”

Getting the GeoTargetting Script Installed on Your Server

Now that you have the above information, the next step is to install the script on your server.

  • Step 1 – Download the binary format from maxmind’s website.
  • Step 2 – Uncompress the file using gzip, winrar, or whatever program you use to unzip files.
  • Step 3 – Download and uncompress EasyDayGeo.zip. There are two files in this package, geoip.inc and geo.php. The first file contains the class necessary to access the API, the second file contains the calls to the API. In this case, we will just want the two letter name of the country that the visitor is from (US, etc).
  • Step 4 – Create a directory named “inc” in the root folder of your website. You should be able to access this folder by going to www.whateverdomain.com/inc/.
  • Step 5 – Open geo.php and change ‘YOUR/PATH/TO/inc/GeoIP.dat’ to reflect the actual path of “inc” folder you just created on the server. Once again, this should look something like /home/public_html/mb/inc/GeoIP.dat when it’s done.
  • Step 6 – Upload the three files: GeoIP.dat, geoip.inc, and geo.php to the “inc” folder.
  • The script is now installed on your server. In this final section, you will call the script and use it as you see fit.

    Using the GeoTargetting Script

    Now that the script is installed on your server, you need to use it to determine the visitor’s country. Since there are literally thousands of possible combinations available, I will just stick to the simplest one that pertains to the gambling industry. Is my visitor from the US? If so, I want to show them US only content. If not, I want to show them other content.

    At the top of your page, in the head section, add the following code:

    <?php include ('YOUR/PATH/TO/inc/geoip.inc'); global $country; ?>

    Remembering, of course, that you need to change the path to reflect your ABSOLUTE path. Next, wherever you want to geotarget content, add the following snippet.

    <?php if($country=='US'): ?>
    /// US CONTENT GOES HERE
    <?php else: ?>
    /// NON-US CONTENT GOES HERE
    <?php endif; ?>

    That’s It

    A few points to note. For SEO purposes, google only crawls with US IP addresses, so any content you geotarget away from US visitors will not be crawled by googlebot. Also, AOL visitors (I guess a small % still use AOL) will show as US visitors regardless of what country they are visiting from. This has to do with the location of the AOL servers.

    Feel free to comment with suggestions or better yet, post a link to where you are using this script so other’s can see it in action.

    Coming soon, the re-release of the wordpress geotargetting plugin.

{ 3 comments… read them below or add one }

iGLOBAL NiCK 10.09.09 at 5:27 pm

Mike, thanks very much for this tutorial on how to setup Maxmind and use it, you made it very easy and clear to understand, I have not yet installed this but plan on doing it within the next few days. I will let you know if I have any problems, and thanks again for everything! A+ for effort.

Nick

Kaus 07.13.10 at 9:47 am

hmmm I cant seem to get this to work Mike. I uploaded and made sure the file path was proper. Ads are showing the else and not the US or Canadian.

You can view it here

http://www.bestslotsonline.org/winning-at-slots/

I used

////US Content Here

////CA Content Here

///All Other Content Here

What am I missing?

Kaus 07.13.10 at 9:48 am

darn – it didnt use the code – anyway same bits as you have above except when it came to the ca content I used php elseif($country==’CA’):

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>