About Page Site Statistics Reference Guide

:bookmark: This is a reference guide for describing how the statistics on the /about page are calculated, and where to find the Ruby code for each statistic.

:person_raising_hand: Required user level: All users

About Page Statistics

All Discourse sites have a built in /about page (for example, here is the about page for Meta) that contains a list of admins and moderators for the site along with a few statistics about the site itself.

These statistics include all users, including admin and moderator accounts. Some statistics will also include anonymous accounts (if enabled on the site).

If the share anonymized statistics site setting is enabled (by default this setting is enabled) the “Site Statistics” on the /about page will be exposed as a json file that can be retrieved at /about.json.

If a site is public, the /about page along with these statistics will be available publicly as well.

:gem: The Ruby code for the core statistics is located in: discourse/lib/statistics.rb. The Stat model that orchestrates core and plugin stats is in discourse/app/models/stat.rb.

Below is a description of how each of these statistics are calculated.

Topics

The number of topics that were created within the indicated timeframe. This statistic does not include unlisted topics or personal messages.

topics = Topic.listable_topics

{
  last_day: topics.where("created_at > ?", 1.day.ago).count,
  "7_days": topics.where("created_at > ?", 7.days.ago).count,
  "30_days": topics.where("created_at > ?", 30.days.ago).count,
  count: topics.count,
}

Posts

The number of posts that were created within the indicated timeframe. Personal messages are included here and counted as regular posts.

{
  last_day: Post.where("created_at > ?", 1.day.ago).count,
  "7_days": Post.where("created_at > ?", 7.days.ago).count,
  "30_days": Post.where("created_at > ?", 30.days.ago).count,
  count: Post.count,
}

Sign-Ups

The number of valid users who have signed up for new accounts within the indicated timeframe. A “valid user” is a real user who is also activated, not suspended, and not silenced. If must approve users is enabled, only approved users are counted.

def self.valid_users
  users = User.real.activated.not_suspended.not_silenced
  users = users.approved if SiteSetting.must_approve_users
  users
end

{
  last_day: valid_users.where("created_at > ?", 1.day.ago).count,
  "7_days": valid_users.where("created_at > ?", 7.days.ago).count,
  "30_days": valid_users.where("created_at > ?", 30.days.ago).count,
  count: valid_users.count,
}

:gem: A real user is defined here: discourse/app/models/user.rb — it excludes system/bot users and anonymous user shadow accounts.

Active Users

The number of valid users who have visited the site within the indicated timeframe. Uses the same valid_users filter as Sign-Ups (excludes inactive, suspended, and silenced users). Includes anonymous mode users, but does not include users without an account.

{
  last_day: valid_users.where("last_seen_at > ?", 1.day.ago).count,
  "7_days": valid_users.where("last_seen_at > ?", 7.days.ago).count,
  "30_days": valid_users.where("last_seen_at > ?", 30.days.ago).count,
}

Participating Users

The number of valid users who have performed an action (created a topic, post, like, etc.) within the indicated timeframe. If chat is enabled, users who sent chat messages or added chat reactions are also counted.

{
  last_day: participating_users_count(1.day.ago),
  "7_days": participating_users_count(7.days.ago),
  "30_days": participating_users_count(30.days.ago),
}

:gem: The full implementation is in discourse/lib/statistics.rb.

Likes

The total number of likes all topics and posts have received within the indicated timeframe.

likes = UserAction.where(action_type: UserAction::LIKE)

{
  last_day: likes.where("created_at > ?", 1.day.ago).count,
  "7_days": likes.where("created_at > ?", 7.days.ago).count,
  "30_days": likes.where("created_at > ?", 30.days.ago).count,
  count: likes.count,
}

Visitors and EU Visitors

When the display eu visitor stats site setting is enabled, the about page will also display estimated visitor counts (total and EU-based). These are calculated by combining logged-in user visit data with estimated anonymous visitors based on page view ratios.

:gem: See the visitors and eu_visitors methods in discourse/lib/statistics.rb for the full calculation.

Chat Messages

The number of chat messages sent across all chat channels. When chat is enabled, the following statistics are also registered: chat users (distinct users who have sent messages) and chat channels (open channels).

These stats are registered as plugin stats by the chat plugin via register_stat in plugins/chat/plugin.rb. The underlying queries are in plugins/chat/lib/chat/statistics.rb.

Last edited by @JammyDodger 2024-08-29T09:46:04Z

Last checked by @hugh 2024-07-23T11:32:47Z

Check documentPerform check on document:
6 Likes