Find users who read specific topics

How can I use data explorer plugin to find out if users read/engaged with certain topics and certain categories?
I tried searching the forum but no luck on finding it yet.

I also need the users email and first/last name to be in the output.

3 Likes

For the users having read a certain topic, you need to join on the “topic_user” table.

For the categories, you need to filter the topics of said categories :wink:

For Topic Participants you could use something like this

-- [params]
-- null string_list :topic_id
WITH user_data AS (
  SELECT u.username, ue.email, tu.topic_id FROM users u
    LEFT JOIN topic_users tu ON u.id = tu.user_id AND tu.posted = true
    LEFT JOIN user_emails ue on u.id = ue.user_id
)
SELECT * FROM user_data WHERE topic_id = :topic_id

You would then just need to enter the relevant topic id in the box that is required.

4 Likes

I specifically linked to one there. It looks pretty close to what you are asking for. Can you run it and tell us what more info you need and we can likely edit it.

1 Like

Sorry about that, never noticed

I dont understand why user is a number, where I should specify the topic id,
and also when I run the query nothing shows up? (probably because I dont know how to use it)

Thank you, this one is going to be pretty useful for me in the future when my forum is bigger.
Does this also include people who have liked the posts in the topic, or only those who replied?

If it does not include likers, how can we add them?

You can get more data from that query by selecting for more fields from the topic_users table. To find whether the user liked a post, or posted in the topic, try this:

-- [params]
-- null string_list :topic_id
WITH user_data AS (
  SELECT u.username, ue.email, tu.topic_id, tu.posted, tu.liked FROM users u
    LEFT JOIN topic_users tu ON u.id = tu.user_id AND tu.posted = true
    LEFT JOIN user_emails ue on u.id = ue.user_id
)
SELECT * FROM user_data WHERE topic_id = :topic_id
2 Likes

This only shows me if the users who posted in the topic likes the post. Doesnt show if someone just comes in likes and leaves without posting?

That’s right. You can alter the query so that it doesn’t only select users who have posted by removing this part:

AND tu.posted = true

Try this:

-- [params]
-- int :topic_id

WITH user_data AS (
  SELECT u.username,
    ue.email,
    tu.topic_id,
    tu.posted,
    tu.liked
    FROM users u
    JOIN topic_users tu ON u.id = tu.user_id 
    JOIN user_emails ue on u.id = ue.user_id
    ORDER BY tu.last_visited_at DESC
)
SELECT * FROM user_data WHERE topic_id = :topic_id
4 Likes

Thank you so much brother you just sent me exactly what I needed. Not only does it scrape users who liked and commented, but it also shows me who viewed it!!

Respects!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.