Monday, November 18, 2013

Creating A Personalized Experience for Your Site Visitors: How to Detect Visitors' Country


So this is the first blog of a series on how to create a personalized experience for your website visitors. This part of the series will take care of getting and using the country of the visitor through 2 different ways:

1- HTML5 Geo-Location:


How it works?
As part of the html5 specification browsers need to support this functionality. And although both chrome and firefox use the google geolocation service in their implementation, the implementation can be done in different ways in the future following the specs. I have read somewhere that the Safari on IPhones actually uses the GPS on the device to provide the location information instead of WiFi-triangulation or cell-site geolocation.

Pros: 
  • Can get you more accurate information, you can get latitude and longitude of a visitor, so you can tell the city and even the street they are in.
  • Following the html5 specification, hopefully in the future the browsers implementation will be more solid than it is today.

Cons:

  • Will prompt the user asking to share location information. in the case of getting only the country, this could be an overkill. 
  • The prompt is shown in different places in different browsers and can go unseen which creates a horrible user experience IMHO.
  • Troublesome to code.

Example:
Check the fiddle in the link below for a simple example on using html5 geolocation:
http://jsfiddle.net/3amzooo/7ZA7p/

Read More:
http://www.w3schools.com/html/html5_geolocation.asp

2- Use of an IP range DB service API:


How it works?
This method works by storing IP ranges that belong to each country in a database, once you query using the visitors IP, it will return the country that is assigned the IP range that the IP your inquiring about (visitor's IP) falls within . 


Pros:

  • Quick method, doesn't need user consent.

Cons:

  • Might sometimes get wrong information since it's based on the database of IP address Ranges associated with each country.
  • Cannot get detailed information like latitude, longitude.
Example:
Check the fiddle in the link below for a simple example on using an API that uses a database to tell the location:
http://jsfiddle.net/3amzooo/kG4vC/

Read More & Resources:
http://freegeoip.net/
http://dev.maxmind.com/geoip/legacy/geolite/

No comments:

Post a Comment