View count difference in category vs data-explorer

AI-generated summary

Users are discussing discrepancies in view counts between the topic_views table and the topics.views field in Discourse’s Data Explorer. philip-ellis-sp noticed that topic_views returns fewer views than topics.views. JammyDodger explains that topic_views records only the first view per user or IP, while topics.views increments every 8 hours (configurable) and thus accumulates more views over time. JammyDodger also mentions the newer topic_view_stats table, which provides daily aggregated view data for both logged-in and anonymous users, though historical data is limited. d4v1d asks why some topics show 0 views despite having comments, attaching a screenshot of a JSON result, but no direct explanation is given in the thread. Mike_Taku adds that topics.views is a cumulative total that includes repeated and guest views not always captured in topic_views, hence the higher count. The key takeaway is that the two metrics serve different purposes: topic_views tracks unique user/IP interactions, while topics.views reflects total accumulated views over time, including recurring visits.

I’m using data explorer to count the number of views on a category using the topic_views table, but when I count the number of views for that category vs the number of views on the topic (topic.views) the number of views in the topic_views table is much less. Any idea why this is?

The topic_views table only records the first view of a topic for each user (or IP Address for anyone not logged in), whereas topics.views from the topics table records one new view every 8 hours (default, but configurable using the topic view duration hours admin setting).

We do have a new table to collect topic view data that can be reported on over a timeframe, which may also be of interest (quite new still, so the data won’t go back too far). That’s in the topic_view_stats table, and can give an aggregate amount of views per topic (for both anon and logged in users) per day.

hi @JammyDodger , i noticed that some topic Views are 0 but there are comments inside, do you know why?

Hi there, I hope you are doing well.
The difference in view counts is likely because the topic views table tracks individual view records (like per user or IP), while the views count in the topic table is a total that includes all views. This total might also account for repeated or guest views that aren’t always in topic views. So, the topic table usually shows a higher, more complete view count.
Thank You,
Mike Taku.