Repository navigation
Count daily.dev visits per blog article and collect YouTube videos on the Analytics Content view - #9685
Count daily.dev visits per blog article and collect YouTube videos on the Analytics Content view#96853mdistal wants to merge 2 commits into
Conversation
… the Analytics Content view
[Medium impact] The PR changes collection and reporting within the Analytics Content workflow. The localization requirement must still be satisfied before merging. SummaryAdds daily.dev visits per article and optional daily YouTube counts to the Content view.
Reviews (2) · Last reviewed commit: "Clear dropped daily.dev counts, read a r..." · Reviewed by Greptile |
Visual recap — generation failedRecap authentication failed — |
… and key channel history by ID
There was a problem hiding this comment.
Builder reviewed your changes and found 3 potential issues 🟡
Review Details
Incremental Code Review Summary
This update adds channel-ID deduplication for YouTube collection, adjusts daily.dev snapshots to write explicit zeros, improves YouTube dashboard grouping/baselines, expands coverage, and adds a changelog entry. The previously reported duplicate-channel write failure is fixed and its review thread has been resolved. Risk remains High because the PR adds API-key-backed external collection and data persistence.
New findings
- 🟡 The daily.dev GA4 source regex matches the substring in unrelated custom
sessionSourcevalues, which can overcount attributed visits. - 🟡 YouTube results have no channel-list fingerprint, so a fetch finishing after settings change may save data for channels no longer configured.
- 🟡 The chart groups by channel title rather than stable channel ID, merging distinct channels that share a title.
- A non-JSON 403 can be mislabeled as an invalid API key; this low-severity error-reporting issue is also included for filtering.
The existing persisted-data and dashboard patterns remain sound overall. 🧪 Browser testing: Skipped — the browser-test-planner agent is unavailable.
| const MAX_REPORT_ROWS = 100_000; | ||
|
|
||
| const TAGGED_LANDING = "[?&]via=dailydev(&|#|$)"; | ||
| const DAILY_DEV_SOURCE = "daily[.-]?dev"; |
There was a problem hiding this comment.
🟡 Daily.dev source filter matches unrelated source names
sessionSource is a free-form GA4 value, but this partial regex accepts dailydev or daily-dev anywhere in it. Unrelated values such as notdailydev can therefore be attributed as daily.dev traffic; anchor the match and require source/domain boundaries or match the intended source values explicitly.
Additional Info
Reported by one independent review agent; confirmed in the GA4 dimensionFilter added at line 18.
| case "builder_blog": | ||
| case "signups": | ||
| case "youtube": |
There was a problem hiding this comment.
🟡 Channel changes are not guarded against stale YouTube runs
The YouTube step has no configuration fingerprint, and its result omits one, so completeContentRun cannot reject a fetch that finishes after the saved channel list changes. That run can persist removed channels and mark the step succeeded, delaying collection of the new list until a later scheduled run; fingerprint the configured channels and return it in the outcome.
Additional Info
Reported by one independent review agent; verified against completeContentRun's existing fingerprint check.
| "source": "first-party", | ||
| "width": 6, | ||
| "tab": "YouTube", | ||
| "sql": "WITH reads AS (SELECT s.item_id, s.metric, s.metric_date, s.value, MAX(s.value) OVER (PARTITION BY s.item_id, s.metric ORDER BY s.metric_date ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS previous, MIN(s.metric_date) OVER (PARTITION BY COALESCE(i.metadata::jsonb ->> 'channelId', ''), s.metric) AS channel_first_read, substr(i.published_at, 1, 10) AS published, COALESCE(i.author, 'No channel') AS channel FROM analytics_content_metric_snapshots s JOIN analytics_content_items i ON i.id = s.item_id WHERE i.source = 'youtube' AND s.metric IN ('youtube_views')), gains AS (SELECT channel, to_char(metric_date::date - 1, 'YYYY-MM-DD') AS date, value - COALESCE(previous, CASE WHEN metric_date > channel_first_read AND published >= channel_first_read THEN 0 END) AS views FROM reads) SELECT date, channel, SUM(views) AS views FROM gains WHERE views IS NOT NULL AND (date < to_char(CURRENT_DATE, 'YYYY-MM-DD') AND ('{{timeRange}}' IN ('', 'all') OR ('{{timeRange}}' = '7d' AND date >= to_char(CURRENT_DATE - INTERVAL '7 days', 'YYYY-MM-DD')) OR ('{{timeRange}}' = '28d' AND date >= to_char(CURRENT_DATE - INTERVAL '28 days', 'YYYY-MM-DD')) OR ('{{timeRange}}' = '90d' AND date >= to_char(CURRENT_DATE - INTERVAL '90 days', 'YYYY-MM-DD')) OR ('{{timeRange}}' = 'custom' AND date >= '{{timeRangeStart}}' AND date <= '{{timeRangeEnd}}'))) GROUP BY date, channel ORDER BY date, channel", |
There was a problem hiding this comment.
🟡 YouTube daily gains merge channels that share a title
The query labels and groups the series by i.author (the channel title) while its baseline is partitioned by metadata.channelId. Distinct channels can share a title, causing their gains to be combined into one series; aggregate by stable channel ID and use the title only for display.
Additional Info
Reported by two independent review agents (severity differed low/medium); verified in the chart SQL at added line 616.
Problem
The Analytics Content view shows each Builder blog article's pageviews, search traffic and signups, collected once a day. Two places Builder's content reaches developers aren't in it. daily.dev, a developer news feed, links to blog articles, but the view can't say how many readers it sends each one. And Builder's and Codevolution's YouTube videos aren't in Analytics at all, so the view can't say which videos are gaining views. This is the second phase of the Content view plan: daily.dev from GA4, and YouTube through a YouTube Data API key.
Approach
via=dailydevto the links it sends out. A newdaily_devcollection step asks the collection's own GA4 property for sessions by day and landing page (with its query string), on the blog's host and path, that either carry that tag or come from a daily.dev source, and matches each landing page to its article the way pageviews already do. It needs no new connection, so it's on by default. Like pageviews, it writes every article's count for every day it reads, 0 included, so when GA4 lowers or drops a count on a later read, the stored one is replaced. The Articles table shows a blank before the step has ever collected.youtubestep reads public counts with a YouTube Data API key saved under a new Data Sources entry, YouTube. For each channel in the collection'syoutube.channels(a channel ID or an@handle, up to 20; a channel named twice is read once), it looks up the channel's uploads playlist, pages through it 50 videos at a time, and reads each video's views, likes, comments and length, 50 at a time. Each video is stored as ayoutubeitem with its channel's ID, and its counts as "views to date" values dated the day they were read. A count the channel hides gets no row instead of a 0. A whole read costs about one quota unit per 25 videos: about 83 of the key's free 10,000 a day for Builder's and Codevolution's 1,967 videos. The step is off until an admin names channels and turns it on.What changed
server/lib/content-metrics/steps/daily-dev.ts(new): the GA4 report and article matching. Like pageviews, it refetches the last three days each run and backfills 90 days on its first run or when the GA4 property changes.server/lib/youtube.ts(new): the YouTube Data API client. It names a missing key as not set up (424), and a refused key, spent quota, unknown channel or a channel with more than 10,000 uploads as failures, so the step never stores a partial list.server/lib/content-metrics/steps/youtube.ts(new),collect.ts,config.ts: the step, registration, and thedailyDevandyoutubesettings. Saved settings from before read as daily.dev on and YouTube off.actions/configure-content-collection.ts:dailyDev,youtubeandyoutubeChannels; omitted settings keep their saved values.server/lib/credential-keys.ts,app/lib/data-sources.ts,server/routes/api/test-connection.post.ts: theYOUTUBE_API_KEYcredential, its Data Sources entry with setup steps, and a connection test that makes one cheap API call.seeds/dashboards/content-view.json: the YouTube tab, the daily.dev column, and the Sources and Missing data rows.changelog/: a What's new entry for both.The reasons behind these choices are here rather than in code comments, which this repo doesn't take.
Safety and operations
keyparameter, and never written into an error message or a run's detail.Verification
main:oxfmt --checkandoxlinton the changed files, the Analytics typecheck, eight Analytics spec files (174 tests), andpnpm guards. All passed. CI runs again on this head.Not yet verified: either step against real data, which runs only after merge. On beta, the plan is to save the key for the Builder.io workspace, set the two channels, run both steps, and compare a few articles' daily.dev visits and a few videos' views with GA4 and YouTube.
Checked by hand with the new key on Nov 23: both channels resolve (
@Builderio, 151 videos; Codevolution, 1,816), a full read of both costs about 83 units, a made-up handle returns no channel, and a bad key comes back asAPI_KEY_INVALID, which the client reports as a refused key.Review focus
via=dailydevtag on the landing page, or a session source matchingdaily.dev. Does it miss daily.dev traffic or catch traffic that isn't?Known limits
Follow-ups
🤖 Generated with Claude Code