Blog

ExpressionEngine: Total Guests and Most Visitors

Have you ever wondered how an ExpressionEngine site decides how many guests and visitors you have at any given time? What about the way it tracks those stats over time? At the bottom of forum pages, and in the old default templates EE installed, you often got a little blurb like this:

The most visitors ever was 1154, on August 26, 2009 03:45 PM
Total Logged-in Users: 1
Total Anonymous Users: 0
Total Guests: 55

So, what does that information really mean and how is it calculated? There is only basic documentation on it from EllisLab, so here’s the inside scoop in full technicolor detail, taken directly from the code for EE 2.3.1:

Every time EE builds a page, whether that page is cached or not, ExpressionEngine updates its stats. But wait… it’s already a little tricky: this assumes you have “enable_online_user_tracking” set to yes.  You probably do.

When ExpressionEngine updates its statistics (the magic happens in /libraries/Stats.php), EE takes a look only at activity from the past 15 minutes. (There is no way to change this time period except by hacking the core—so your site’s stats are going to be compared on the same scale as anyone else’s EE site, unless they are sooper-l33t.)  Information about current online visitors is kept in a table called “exp_online_users”. Old entries get cleaned out approximately every 20 page views, but regardless off the table’s state, visitors will never be over-counted even if the table hasn’t been cleaned, because the 15-minute span of time is enforced by each database query for online users.

Interesting side note and possible bug: You might have “dynamic_tracking_disabling” enabled to help with large traffic spikes. This setting says, if there’s too much traffic, you want EE to disable tracking to speed up your site. But ironically, once you hit that certain amount of traffic, this setting means you will stop updating the “exp_online_users” table.  In other words, you won’t keep tracking that you have large amounts of users, which means EE will soon think there are fewer users, and then you’ll start tracking them again.

In any case, assuming you ARE tracking stats (and therefore users) at this point, EE looks at the current entries in the “exp_online_users” table, and sorts them into: “logged-in” people (public and “anonymous”) and “guests”.  A guest is considered a new person if they are visiting from a particular unique IP address. So, multiple people from one office sharing one IP address, count as one guest—until they log in. And people who don’t specify an IP address or who spoof one—it’s possible—count as one unique visitor.

Meanwhile, a single search engine crawler that connects from 10 different IP addresses or a person behind a proxy with 10 rotating IP addresses, look like 10 guests, assuming all visits happen within 15 minutes.

Important to note: if you log in to a site, you were probably counted as a guest, and you now count as a logged-in user. When you log in via the control panel, nothing removes the guest version of you until 15 minutes expires (but if you log out, you are removed as a logged-in version of you). If you log in or log out via the forums or the member section of your site, this cleanup does happen, so it’s likely it’s a very small issue in your site stats.

So, that’s members and guests. What’s an anonymous user? That’s someone who has logged in, but who has selected to be “hidden” from the list of people online—this is only the case if you have made that checkbox available on the login screen and they have checked it. Anonymous users are not counted as guests. (Anonymous users are visible to superadmins who see all and know all.)

If the number of guests and the number of logged in users (public and anonymous) all together is the largest amount it’s ever been, the “exp_stats” table is updated with your new “high score” and the current time. But if it’s not, “exp_stats” is still updated, with only the “last_visitor_date”. This happens on every page load.

Side note 2: If you’re logged_in, your own profile will update the “last_visit” information for your own account, whether or not stats are turned on, from somewhere else in the code. So it’s possible to have members with more recent last visits than your site’s last visit, if you’ve disabled tracking. Be aware.

Last facts: There’s no way to reset your site’s stats without directly accessing the database. And statistics are tracked on a site-by-site basis, so if you’re running Multi-Site Manager, visitors to one site are not counted with visitors to another (but the table is cleaned for all sites at once).

And that’s how total guests and most visitors work in ExpressionEngine.

Comments

Have a Project for Us?

Get in Touch