How many viewers viewed a topic during a certain period?

I am trying to figure out a way to find out how many viewers (logged in or not) viewed a certain topic during a certain period. I searched for an answer but couldn’t find an exact solution. Using the Data Explorer, I tried to study the tables that mention the viewers and try to use SQL to filter out the result; however, I have not been able to get to know exactly how many users viewed a certain topic during a certain day for example.

I will explain the tables that I have studied! You can correct me if I’m wrong or if there’s something that I can add to fix it, please! Thanks!

The table topic_views lists the first_viewed_at and so it’s not possible to know if the user visited the topic for a second time or not; however, although the table topic_users lists the first_viewed_at as well as the last_viewed_at the last view might be a third or fourth view after the period that I’m inquiring about. For example, if today was their last view and before yesterday was the first view, I won’t be able to know if the user viewed the topic yesterday. The views from the topics table doesn’t help much because it doesn’t mention when; nor does the post_timings table either because it doesn’t mention when the reading occurred.

Is there any other table or method that I missed?

Thank you so much! (:

2 Likes

If you have access to the rails console, you could try:

ssh root@example.org
cd /var/discourse
./launcher enter app
rails c
Topic.find(<topic-id>).views

But this is subject to the site setting topic view duration hours, so new topic visits are counted after N number of hours. Check this previous discussion about this Topic_views vs Topic.views - #6 by vinothkannans

You could also try tracking views with Google Tag Manager.

1 Like

Thank you so much for your answer! I have a question please.

It says that the topic.views is an integer count but this is not going to help me know when these counts occurred, right? So I won’t be able to know the number of users who viewed a topic during a certain day?

Thank you for the suggestion! Do you think it will be as accurate as the results generated by Discourse Data Explorer? Am I going to be able to get the number of online users for example? Or the number of users who viewed a topic from 6AM until 11PM in a certain day? (:

Thank you!

No, I don’t think you’ll be able to get this info from the Topic.views.

Lots of things can be tracked with GTM. You should be able to get the number of online users as well as the number of users that viewed your site between certain hours. But you need to configure your tags and triggers correctly, check Page view triggers - Tag Manager Help

1 Like