I would like to query the audit logs to obtain usage stats for all dashboards created by a particular user. In particular I would like to know which unique people, other than the creator, has viewed each dashboard created by this particular user, and how many times they have viewed it.
If you're connected to the Metabase database, you can get this from the view_log, report_dashboard, and core_user tables. See query below:
select
count(*) as view_count,
report_dashboard.id as dashboard_id,
report_dashboard.name as dashboard_name,
core_user.id,
core_user.first_name,
core_user.last_name,
core_user.email
from
view_log
join
report_dashboard on view_log.model_id = report_dashboard.id
join
core_user on view_log.user_id = core_user.id
where
report_dashboard.creator_id = {{creator_user_id}}
and view_log.user_id != {{creator_user_id}}
and view_log.model = 'dashboard'
group by
core_user.id,
core_user.first_name,
core_user.last_name,
core_user.email,
report_dashboard.id,
report_dashboard.name
Hi @josiah44,
It's very interesting! Thank you so much for the query. But how we can connect to Metabase database ?
In "Browse Data", I only see Sample Database and another databases of my company.
First, you have to be using metabase's "On-Prem" (self-hosted) solution. You cannot do this with the cloud solution.
If you're self-hosting, you can point to the metabase database as a SOURCE to itself. We've lovingly named ours "Metabase-ception"). For reference, ours is a PostgreSQL database. I don't honestly know if Metabase has other options for the Database type for self-hosted dbs.
@AndrewMBaines I don't think that's the case. We have both a paid instance and a free self-hosted instance. For the self-hosted instance, we still report from the view_log table.
Depends upon your version of Metabase. Just checked on a customer install of 50.18. Latest entry in View Log is 8th July. I'd guess that's about the time I upgraded them to 50.x.
What version are you running?