swisspig.net - To hell with the pig... I'm going to Switzerland.

How Long Are Visitors Viewing My Pages? (Saturday, August 26, 2006)

Wow! I've discovered a lot of interesting stuff over the past two evenings. You may have noticed a new entry on the main menu for recent activity, which shows data about what visitors have been up to for the last twenty-four hours.

Up to this point, I've been spending a lot of time on the command line with a complicated grep command viewing the recent activity on my site, while filtering out all the bots, hack attempts, and my own debugging activities. And for each new user, I end up trying to figure out where they came from, what they were looking for, and where they are located. And even then, I would have no idea how long they stayed before clicking "back" in their browser.

No longer. As an exercise in improving my database skills, learning AJAX, brushing up on my DHTML, and figuring out how to locate IP addresses, I decided to build the activity page. Using AJAX, my visitors' browsers periodically let my server know that they are still viewing it, and as a result, I am able to tell how long they stay on a particular page, with a fair degree of accuracy. Using DHTML, I was able to create advanced "tool tip" style pop-up windows with additional information about each log entry, without cluttering up the normal display. Regular tool tips were inadequate because they didn't allow me any control, in particular to wrap long lines, and to select text. With DHTML, it was no trouble at all. Just mouse over the IP address for detailed information about the visitor, and mouse over the referrer to see the full URL.

And speaking of detailed information, part of that information is the approximate location of the visitor. There are a number of projects, tools, and widgets out there that will tell you what country your visitor is from, but since most of the visitors I care about are from the United States, I was hoping for a big more granularity. My preferred IP Address Locator is hosted by Geobytes, but I only just noticed that they have a web service. Instead, I downloaded the GeoLite City database and API from MaxMind. The GeoLite database is free, and I can host it myself. It is not as accurate as the commercial database that they offer, but it is certainly good enough, considering the cost.

Update: I figured out how to use the GeoBytes web service, even though it isn't local. It gives more accurate results, and is less load on my server, however I'm not sure how I feel about ever page view on my site being logged by GeoBytes. I'm going to let it go for now, and compare the results between GeoBytes database and the MaxMind database. If MaxMind turns out to be close enough, I'm going to disconnect the GeoBytes database.

—Brian (8/26/2006 12:48 AM)
(0 comments)

Comments

No comments.

Name
URL
Comment
(no html)
 

Disclaimer: Opinions on this site are those of Brian Ziman and do not necessarily
reflect the views of any other organizations or businesses mentioned.