YouTube Analytics model

Traffic sources daily

Where views come from: YouTube search, suggested videos, browse, Shorts feed, external sites and so on. The YouTube Studio "Traffic source types" report.

Grain
date_day x channel_id x traffic_source_type
Built from
  1. 1
    Raw tables
  2. 1
    Staging
  3. 1
    Core
  4. 1
    Analytics
Reads from YouTube Analytics
channel_traffic_source_a3
Ships as
Weld and dbt SQL, open source on GitHub
core.youtube_analytics.traffic_sources_daily
1-- core.youtube_analytics.traffic_sources_daily
2-- Where views come from: YouTube search, suggested videos, browse, Shorts feed,
3-- external sites and so on. The YouTube Studio "Traffic source types" report.
4--
5-- Grain: date_day x channel_id x traffic_source_type. Dates are Pacific Time.
6-- Depends on: staging.youtube_analytics.channel_traffic_source
7--
8-- share_of_views is the source's share of the channel's views that day. For a
9-- longer period re-sum views and divide again.
10
11SELECT
12    date_day,
13    channel_id,
14    traffic_source_type,
15    traffic_source,
16    SUM(views)                  AS views,
17    SUM(engaged_views)          AS engaged_views,
18    SUM(watch_time_minutes)     AS watch_time_minutes,
19    SAFE_DIVIDE(SUM(watch_time_minutes) * 60, SUM(views)) AS average_view_duration_seconds,
20    COUNT(DISTINCT video_id)    AS videos,
21    SAFE_DIVIDE(SUM(views), SUM(SUM(views)) OVER (PARTITION BY date_day, channel_id)) AS share_of_views
22FROM {{staging.youtube_analytics.channel_traffic_source}}
23GROUP BY 1, 2, 3, 4

This model and the 2 it depends on. Deploy them together; refs like {{staging.…}} resolve to the matching folders in Weld, and the dbt view uses source() and ref().

Notes

How it counts. And where it stops.

share_of_views is the source's share of the channel's views that day. For a longer period re-sum views and divide again.

Raw tables it reads

  • raw.youtube_analytics.channel_traffic_source_a3

Put YouTube Analytics in front
of your agents.

Connect YouTube Analytics, deploy the models, and ask questions in Claude, Cursor or ChatGPT. Free for 14 days, no credit card.