Data Explorer - Find users who read specific topics


(Henry Cooper) #1

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.


(Régis Hanol) #2

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:


#3

Are you looking for something like What cool data explorer queries have you come up with? ?


#4

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.


(Henry Cooper) #5

Yes I looked through that and got some really awesome ones. But couldn’t find the one I posted about


#6

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.


(Henry Cooper) #7

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)


(Henry Cooper) #8

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?


(Simon Cossar) #9

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

(Henry Cooper) #10

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?


(Simon Cossar) #11

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

(Henry Cooper) #12

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!


(system) closed #13

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