# Is it possible to see the topics a user has viewed?

**URL:** https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [June 20, 2020, 4:08am UTC](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413 "2020-06-20T04:08:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![metadiscourseuser](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@metadiscourseuser](https://meta.discourse.org/u/metadiscourseuser)
#### Post date: [June 20, 2020, 4:08am UTC](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413/1 "2020-06-20T04:08:45Z")

</div>

I’m analysing the user stats & activity on our forum.

I’d like to see the specific topics a user has viewed. So far the most detailed activity I can find about the user is just the number of “Topics Viewed” & “Posts Read” in the Admin → Users grids.

I’ve installed the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin to see if there’s more data, but haven’t been able to find anything useful in terms of detailed user activity logs & topic/post access.

TIA

---

<div class="post-metadata">

### Author: ![ditatompel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ditatompel/32/141759_2.png) [@ditatompel](https://meta.discourse.org/u/ditatompel)
#### Post date: [June 20, 2020, 3:43pm UTC](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413/2 "2020-06-20T15:43:35Z")

</div>

Maybe something like:

# Who (logged in user) view specific topic

```sql
-- [params]
-- int :topic_id = 1

SELECT
    title,
    viewed_at,
    tv.user_id
FROM topics t
LEFT JOIN topic_views tv
    ON t.id = tv.topic_id
WHERE category_id IS NOT NULL
    AND tv.user_id IS NOT NULL
    AND t.id = :topic_id
ORDER BY viewed_at DESC
LIMIT 1000

```

# Last 100 topic view by user

```sql
-- [params]
-- int :user_id = 1

SELECT
    tv.user_id,
    title,
    viewed_at,
    views,
    t.user_id
FROM topics t
LEFT JOIN topic_views tv
    ON t.id = tv.topic_id
WHERE category_id IS NOT NULL
    AND tv.user_id = :user_id
ORDER BY viewed_at DESC
LIMIT 100

```

---

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [June 21, 2020, 12:48am UTC](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413/3 "2020-06-21T00:48:10Z")

</div>

> [@ditatompel](#):
>
> Maybe something like

Great queries !

I just upgraded the query’s list in github with your code.  
If you have more queries, don’t hesitate to contribute there. 👍

---

<div class="post-metadata">

### Author: ![metadiscourseuser](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@metadiscourseuser](https://meta.discourse.org/u/metadiscourseuser)
#### Post date: [June 21, 2020, 12:34pm UTC](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413/4 "2020-06-21T12:34:22Z")

</div>

Awesome! Thanks very much, it worked like a charm!
