How to track user activity?

Hi all…

I really need your help to track our user activity with data explorer.

Input : Username and Date

The result from the query that I hope to get is like this,

Username Date topics_created post_created like_received total_words
User A 01-10-2019
02-01-2019
03-01-2019
31-01-2019
User B 01-10-2019
02-01-2019
03-01-2019
31-01-2019
User B 01-10-2019
02-01-2019
03-01-2019
31-01-2019
User C 01-10-2019
02-01-2019
03-01-2019
31-01-2019
User Z 01-10-2019
02-01-2019
03-01-2019
31-01-2019

Thank you very much for your help…

2 Likes

I don’t think the inputs you have listed match the output you are hoping to get. If you would like to get data for a single user, something like the query below might work as a starting point. It’s using Common Table Expressions to make the query easier to read and write. The same pattern could be followed to add more data to the results.

One thing I wasn’t sure of is if you want the sum of the data for a given day, or the number of actions that took place on each day. For example, do you want to know that on 2019-10-31 a user has created a total of 20 posts in all the days they have been on the site, or do you want to know that on 2019-10-31 the user created exactly 3 posts? The way the query is currently structured, it’s returning the latter result.

--[params]
-- string :username
-- date :start_date

WITH target_user AS (SELECT id FROM users WHERE username = :username),
days AS (
SELECT day::date
FROM GENERATE_SERIES(:start_date, NOW()::date, INTERVAL '1 day') AS day
),
topics_created AS(
SELECT
tu.id,
day,
COUNT(tu.id) AS topics
FROM topics t
JOIN target_user tu
ON tu.id = t.user_id
JOIN days
ON t.created_at::date = day
WHERE t.archetype = 'regular'
AND t.deleted_at IS NULL
GROUP BY day, tu.id
),
posts_created AS(
SELECT
tu.id,
day,
COUNT(tu.id) AS posts,
SUM(array_length(regexp_split_to_array(raw, '\s'), 1)) AS word_count
FROM posts p
JOIN target_user tu
ON tu.id = p.user_id
JOIN days
ON p.created_at::date = day
WHERE p.post_type = 1
AND p.deleted_at IS NULL
GROUP BY day, tu.id
),
likes_received AS (
SELECT tu.id,
day,
COUNT(tu.id) AS likes_received_count
FROM user_actions ua
JOIN target_user tu
ON tu.id = ua.user_id
JOIN days
ON ua.created_at::date = day
WHERE ua.action_type = 2
GROUP BY day, tu.id
)

SELECT
d.day,
COALESCE(topics, 0) AS topics,
COALESCE(posts, 0) AS posts,
COALESCE(word_count, 0) AS word_count,
COALESCE(likes_received_count, 0) AS likes_received
FROM days d
LEFT JOIN topics_created tc
ON tc.day = d.day
LEFT JOIN posts_created pc
ON pc.day = d.day
LEFT JOIN likes_received lc
ON lc.day = d.day
ORDER BY d.day
6 Likes

I want the number of actions that took place on each day, exactly like the query you give it to us…

Thank you very much sir, for your help… It really helps us…

2 Likes

To increase user activity, we plan to hold a challenge, who is the most active user in our forum, to be rewarded.

Therefore, we wanted to get some additional data, to make the challenge even more interesting.

The data we have, using the query from @simon is Topics, Posts, Words Count and Likes Receive

Some additional data include:

  • Likes Given: How many likes were given
  • Visit: How many times the user opens the forum
  • Read Time: How long the user is in the forum
  • Following and Followers
  • Topics View: How many topic views the user gets for all the topics he created…
  • Topics replies: How many replies (posts) the user gets for all the topics he created…

Please help us, so that we can get these additional data.

For the weighting of each item, we plan to use excel. Is there any advice on how to weight each item to choose the winner?

We want to make this challenge serious but fun. The best users are the combination of most active, most helpful, and most popular. :partying_face: :partying_face: :partying_face:

Once again, thank you very much for your help.

Note: Can we get the data in groups, so we only enter the group id. Our plan is that we will put all participants into a group. This time, we have to enter the participant’s user id one by one

1 Like

Hey @manchestermania

A fellow Mancunian here :slight_smile:
My company are looking to run a similar competition internally to boost engagement with our community by the employees.

Did you manage to run the competition? How did you end up pulling the data? And how did you weight the different engagement metrics in the end?

Would love to chat with you!

Thanks
Julia

2 Likes