GeoIP tracking with Google APIs

April 3rd, 2009 by kowsik

If you want to track visitors to know where they are coming from, the normal un*x’ish way of doing this is to grab maxmind’s geoiplookup (or apt-get/rpmfind) and then run it against the web server logs. That’s so not Web 2.0. *ugh*

Google’s hosted JavaScript API’s makes this so much easier. All you have to do is include:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>

in your web page and voila’, you have the client location. How? If you directly navigate to the jsapi, you’ll see the following:

google.loader.ClientLocation

which pretty much gives you all you need to locate the user. Do a jQuery post to your web server and you know exactly where the user is coming from. Here’s a better example. The map below uses Google’s Map API to show you where you are viewing this blog from.



Posted in JavaScript | Permalink | Trackback

4 Responses

  1. Cd-MaN

    Sounds very interesting. Unfortunately it always gives null to me, even though I’m not trying to do anything to hide myself :-)

    Tried it from two different IP addresses (from two different provides) in Romania.

  2. kowsik

    Can you try navigating directly to the jsapi URL and see if you have the google.loader.ClientLocation line?

  3. Cd-MaN

    I did that and it said “google.loader.ClientLocation = null” from both of the IPs.

    Update: I’ve tried from a third IP and it also has null. Maybe it is limited to certain countries / ISPs.

  4. kowsik

    Apparently it doesn’t always work. :-(

    http://code.google.com/apis/ajax/documentation/#ClientLocation

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.