如何追踪用户活动?

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…

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

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…

为了提升用户活跃度,我们计划举办一场挑战活动,评选出论坛中最活跃的用户并给予奖励。

因此,我们希望获取一些额外的数据,让挑战活动更加有趣。

我们目前拥有的数据(通过 @simon 提供的查询获取)包括:主题数、帖子数、字数统计和收到的点赞数。

一些额外的数据包括:

  • 已给出的点赞数:用户给出了多少个赞
  • 访问次数:用户打开论坛的次数
  • 阅读时长:用户在论坛停留的时间
  • 关注者和被关注者
  • 主题浏览量:用户创建的所有主题获得的总浏览量
  • 主题回复数:用户创建的所有主题收到的回复(帖子)总数

请帮助我们获取这些额外数据。

关于各项指标的权重分配,我们计划使用 Excel 进行处理。对于如何为每项指标分配权重以选出获胜者,您有什么建议吗?

我们希望这场挑战既严肃又有趣。最佳用户应是活跃度最高、最乐于助人且最受欢迎的综合体现。:tada::tada::tada:

再次衷心感谢您的帮助。

注意:我们能否按群组获取数据,只需输入群组 ID?我们的计划是将所有参与者加入一个群组。目前,我们需要逐个输入参与者的用户 ID。

@manchestermania

这里也有一位来自曼彻斯特的伙伴:slight_smile
我们公司正计划内部举办一场类似的竞赛,以提升员工与社区的互动。

你们成功举办了这场竞赛吗?最终是如何提取数据的?又是如何为不同的互动指标分配权重的?

非常希望能和您交流!

谢谢
Julia