# Counting Pageviews for users (non-staff, non-crawler)

**URL:** <https://meta.discourse.org/t/counting-pageviews-for-users-non-staff-non-crawler/157071>\
**Category:** Data & reporting\
**Created:** [July 7, 2020, 7:24pm UTC](https://meta.discourse.org/t/counting-pageviews-for-users-non-staff-non-crawler/157071 "2020-07-07T19:24:14Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mrjn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrjn/32/121540_2.png) [@mrjn](https://meta.discourse.org/u/mrjn)\
**Post date:** [July 7, 2020, 8:02pm UTC](https://meta.discourse.org/t/counting-pageviews-for-users-non-staff-non-crawler/157071/3 "2020-07-07T20:02:59Z")

</div>

So, something like this? So, would the IP address be null for crawlers?

I want to include:

- anonymous viewers
- logged in users

I want to exclude:

- crawlers
- staff users

```plaintext
-- [params]
-- string :date = '2020-01-01'
-- boolean :staff = false

WITH t AS (
    SELECT date(:date) AS START
),
f AS (
    SELECT id as user_id
    FROM users u
    WHERE u.moderator = 'True' or u.admin = 'True'
)

    SELECT
    user_id,
-- date_part('year', viewed_at) as year,
-- date_part('week', viewed_at) as week,
    COUNT(topic_id) AS topics_viewed
    FROM topic_views, t
    WHERE viewed_at > t.START
    AND ((ip_address is not null AND user_id is NULL) OR
        user_id not in (select f.user_id from f))
    GROUP BY user_id
    ORDER BY topics_viewed DESC
    -- GROUP BY year, week
    -- ORDER BY year, week

```

---

_[View the full topic](https://meta.discourse.org/t/counting-pageviews-for-users-non-staff-non-crawler/157071)._
