Tracking topic views history

AI-generated summary

In a discussion about tracking topic view history, Ayelen_Rives seeks a way to analyze daily views (including anonymous users) for specific topics over time, ideally visualized as a graph or table. Lilly suggests a Data Explorer query using the topic_views table, filtering by topic ID and date range. Ayelen_Rives finds it helpful but notes it aggregates total views rather than breaking them down by day. JammyDodger clarifies a critical limitation: topic_views only records the first view per user/IP, not daily views — making time-based analysis inaccurate. Lilly humorously agrees the table should be renamed topic_first_views and links to a relevant discussion. Ayelen_Rives acknowledges the limitation and thanks everyone, planning to explore the linked thread further. The key takeaway is that current Discourse data doesn’t support granular, daily view tracking per topic due to how topic_views is structured.

Hi!
I’ve been searching for a while but couldn’t find anything similar, not even in the cool Data Explorer queries.

I want to see the history of views/visits that a specific topic has received for a period of time.
Ideally, I’d like to have something like this, but for each individual topic:

I don’t mind if it’s just a table day by day or if it can include a graph (I can build that outside Discourse). I’m also really interested in having all visits (user & anon).

This would help me track and analyze topics usage within certain periods of time (in where I expect more or less activity).

Do you know if is there some data explorer query for this?
Thank you in advance! :raised_hands:

Hi @Ayelen_Rives :wave:

Maybe try this:

-- [params]
-- int :topic_id = 
-- date :start_date = 
-- date :end_date = 

SELECT COUNT(*) AS views
FROM topic_views
WHERE topic_id = :topic_id
AND viewed_at BETWEEN :start_date AND :end_date

you will need to specify the topic id (from the topic URL) and the date range parameters in YYYY-MM-DD format.

Hi Lilly!

It’s useful! I’ll make some research in order to separate data day by day, because it sums up all views during period.

Now I know where to begin :raised_hands: :mag_right:
Thanks!!

Glad that helps you. Let us know if you need more specific queries or more help with it :slight_smile:

I’m afraid I have recently found out that the topic_views table only records the very first view of a topic by a user and not one topic view per user/ip per day.

Unfortunately this makes doing a time-based breakdown on views a little skewed, and can only be done on ‘viewed for the first time’.

Well then the table should be called topic_first_views :sweat_smile: :upside_down_face:

Sorry @Ayelen_Rives , I tried :woman_shrugging:t2: :crying_cat_face:

edit: Found a relevant discussion:

What a pity! Agree with Lilly that the table should be called topic_first_views for disambiguation.

Thanks for the info and thanks Lilly for the try! :raised_hands:
I’ll keep looking on that discussion.