Conteggio delle visualizzazioni di pagina per gli utenti (non staff, non crawler)

Quindi, qualcosa del genere? Quindi, l’indirizzo IP sarebbe null per i crawler?

Voglio includere:

  • visualizzatori anonimi
  • utenti loggati

Voglio escludere:

  • crawler
  • utenti staff
-- [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