Kimler Sidebar Menu

Kimler Adventure Pages: Journal Entries

random top 40

Tracking Online Users

Filed in:Site News

Tracking Online Users

June 8th, 2005  · stk

A "Site Tools" Upgrade

When I finished my little project, yesterday, I wrote:

EXCELLENT!

I've finished the upgrade it's pretty neat ... even if I do say so myself. ;) Check out the "currently visiting" number in the "site tools" area. I've written a PHP/MySQL utility to figure out how long folks are on, what they're reading and where in the World they are! :D

Just today, while working on it, we had visitors from Costa Rica, Netherlands, the US, Australia and Taiwan.

When I realized that IP addresses number ranges correspond to various countries, I thought it would be interesting to discover where our website visitors come from. I first added this capability to the comments and just yesterday, to our real-time "users online" feature. It was a fun project and I learned a lot in the process.

"Users Logged On" = A lie!

The "users online" concept is deceptive, because no-one ever really 'logs on' to your website. What really happens is that a visitor makes a 'request to download' a page from your site. The visitor is only connected during the time that the page is being downloaded. Once the page has been loaded into their browser, the visitor is no longer connected and is viewing a local copy.

Only they know what happens next. You might like to think that they're pouring over the words you so laboriously wrote, but (more likely) they did a quick scan, discarded the page and surfed on to somewhere else.

What's Really Being Measured?

When you see a "user's online" script on a website, they're really counting unique IP addresses and arbitrarily determining how long each page request should be viewed as "being online". The standard time is about 20 minutes. This isn't very accurate in the case where a person requests a page, immediately discards it, and move on to another website. It's why I changed ours to 5 minutes. Note also, that many scripts match the IP address, not dropping the last 3 digits, which will lead to inflated visitor numbers. Let me explain.

An IP address consists of 4 sets of numbers (octets) and looks like 202.188.158.130 (which I just made up). Each octet can range from 0 to 255 and the numbers are significant (designating Class, Network, Host and -because countries are assigned ranges of numbers, which are constantly changing- the country). Because of "proxies", it's possible that each HTTP request from a single visitor can utilize different IP numbers, coming from an assigned pool of IPs for their ISP (AOL is notorious for this). When this happens, generally only the last octet (last three numbers) will change. If you don't account for this in the script, the same user can be counted MULTIPLE TIMES, artificially inflating the number of "users online".

The Way Our Script Works

We utilize a free geopolitical, IP Address database that claims to be 97% accurate. The full IP address of the requesting agent (visitor) is compared against that database and a two-letter country code is returned. The two-letters uniquely determine which of 250 country flags to pull from the image directory that I put together. (That's a lot of flags!)

When a visitor first requests a page, the time of their request is determined and stored in a database. The first three octets are also stored and they officially show up as being an "online user" with the status "new". They have 5 minutes to make make another request on the site. If they don't, they are dropped off the list of "online users". If they do, they remain "online" and the time of their initial request is compared to each subsequent request, bumping up their "minutes online" number. Also, the time that they're considered "online" bumps up to 10 minutes (because I'm pretty verbose, it might take them that long to READ a post! ;) ) If they don't click again within the 10 minutes, they're considered "offline". (So, if you have to run to the bathroom, you've got 10 minutes to do your business, come back, and click another page ... or you lose your spot "online" :D )

I thought it would be fun to see what people are reading, so I've posted a link to the page that was last requested. (If someone is on the main page, there are 7 different articles to read, so it's not possible to determine which one of the seven it is, so it's annotated as "browsing the main page". Likewise, if someone is looking at articles using the monthly archives, it says "browsing by month".)

We value privacy and at no point do we show the full IP address (not that much can be gleaned from it), but there's no value in posting it. We don't get a ton of visitors and you can probably "see yourself" by the flag.

We hope you like the new feature and find the long explanation of some value. (I like to get into the nitty gritty, but I also like to be able to explain, in lay terms, what the heck is going on). Websites don't have to be THAT technical. But boy, they sure can be, if you want them to be! ;)

(Permalink)
Views: 5269 views
5 Comments · GuestBook
default pin-it button
Updated: 13-Jun-2005
Web View Count: 5269 viewsLast Web Update: 13-Jun-2005

Your Two Sense:

XHTML tags allowed. URLs & such will be converted to links.


Subscribe to Comments

Auto convert line breaks to <br />

1.flag Justin Comment
06/09/05
Hi Scott! Long time. I just wanted to ask you a quick question about your "photo zoom" technique that I started using some time ago on my site. I finally got around to redesigning the layout so that only an archive view is presented on the main page. But doing so seems to have created some odd problems for some viewers (a problem I've been unable to reproduce) where now only the first photo will zoom, and the other photos "seizure," as they put it, when you move the mouse over them. I really don't know much about web programming so I'm sure my code is a mess, but I was curious if you'd happened to encounter this problem before?

Thanks! :)
2.flag Sieg Comment
06/09/05
Thats good stuff I cant wait for you to start selling that bit of code, Ive been getting mad hits and would like to find out where people are from as well.
Sieg
Oh and I know how the E.R. thing is for nursing people, my wife is a nurse and she gets pissed when they talk smack that would never fly in a real hospital:)
3.flag stk Comment
06/09/05
Justin - I've replied in a private email. The problem you're experiencing is a manifestation of the fact that the large images you have (800x600) don't have enough room on the page to fully zoom. Anyway, the solution is in my email.

Sieg - Glad you like it! (I see an Italy flag right now ... is that you? Ha ha.) If you want me to install any of these tools on your site, send me an email.

-Scott
4.flag Justin Comment
06/09/05
Thanks! That was EXACTLY what I needed to hear :)

(You were right, the problem can be fixed simply by adding "overflow: hidden;" to bPosts in CSS file for the skin you're using.)

:)
5.flag Comment
06/10/05
Hi Scott,
Yet another cool tool, you'll have to buy a factory to churn these out ;)

Considering the length of your posts, you might want to up the online time to 4 hours :p

¥