Tracking Tableau Viewership with PostgreSQL
Tableau's native "Who has seen this view?" panel is a flat list — no trends, no way to tell if usage is real or just the publisher checking their own work. With direct access to the Tableau PostgreSQL repository, you can do a lot better: turn raw access events into aggregated viewership data your dashboard creators can actually act on. Here's the query I use to power that.
The SQL
WITH access_events AS (
-- Pull only "Access View" events from the last 90 days
SELECT
he.id,
he.created_at,
he.hist_view_id,
he.hist_workbook_id,
he.hist_actor_user_id
FROM historical_events he
JOIN historical_event_types het
ON he.historical_event_type_id = het.type_id -- filter to the event type we care about
WHERE het.name = 'Access View'
AND he.created_at >= NOW() - INTERVAL '90 days'
)
SELECT
w.name AS workbook_name, -- current workbook name, from the live content table
hu.friendly_name AS viewer_name, -- NULL when the workbook has zero views
COUNT(ae.id) AS view_count, -- 0 when no matching access events
MAX(ae.created_at) AS last_viewed -- NULL when never viewed
FROM _workbooks w -- drive from the full content table...
LEFT JOIN hist_workbooks hw ON hw.workbook_id = w.id -- ...so workbooks with no history still show up
LEFT JOIN access_events ae ON ae.hist_workbook_id = hw.id
LEFT JOIN hist_users hu ON hu.id = ae.hist_actor_user_id
GROUP BY w.name, hu.friendly_name
ORDER BY w.name, view_count DESC;
The use case
I built this as the backbone of a self-service "Viewership Analytics" dashboard — KPI tiles, a time-series trend, top-viewers ranking, and a detail table with recency color-coding. The goal was to give dashboard creators direct visibility into how their own content is actually being used, so they can answer "is anyone using this?" on their own, anytime. Driving the query from the full workbook list also means unviewed content shows up right alongside everything else, instead of needing a second query to catch what never got seen.
Things to know before you use this
-
hist_workbooks.idis just the internal ID for that snapshot row, not the workbook itself. If you need a stable way to track a specific workbook over time, usehist_workbooks.workbook_idinstead. This matters more than it sounds like it should: workbook names and even publishing locations can change during development — especially before a workbook lands in its final, published-to-prod state — so tracking by internal snapshot ID or by name alone can silently split what should be one workbook's history into several. -
friendly_nameavailability can vary. It's present onhist_usersin this table, but in other parts of the repository it only lives onsystem_users— worth confirming which table has it populated in your version before you build on top of this. -
Self-views aren't excluded here on purpose. As written, this counts a publisher viewing their own workbook the same as anyone else. Depending on your use case that might be exactly what you want (e.g., an admin dashboard), or it might inflate "most viewed" rankings if you're handing this to creators. If you want to exclude them, add a join to the workbook's owner and filter
hist_actor_user_id != owner_id.
Top comments (0)