YouTube Analytics (Google Cloud)
Connect your Google account with the official
YouTube Analytics API v2
(reports.query).
Data is stored only in new tables impact_yt_analytics_* — no changes to existing analytics tables.
User action flow (on this page)
- Configure Google Cloud — create OAuth Web client, enable YouTube Analytics API & YouTube Data API v3, set redirect URI to match this app (see status panel).
- Set server env vars —
YT_ANALYTICS_CLIENT_ID,YT_ANALYTICS_CLIENT_SECRET, and ideallyYT_ANALYTICS_REDIRECT_URI. - Connect Google — consent screen; we request analytics + readonly YouTube scopes (optional monetary scope for revenue metrics).
- Choose date range — defaults to the last 28 days (API uses
YYYY-MM-DD). - Fetch preset reports — server calls
GET https://youtubeanalytics.googleapis.com/v2/reportswithids=channel==MINEper the official docs. - Optional: custom query — one-off
metrics/dimensions/filters/sort(validated) stored under the same tables with a label you choose. - Review history — each API response is saved as raw JSON plus one normalized row per result row (column names → values).
- Disconnect (optional) — removes OAuth tokens and all stored fetches/rows for your Impact user.
Data flow
Browser → Impact PHP: connect, disconnect, and “fetch” actions hit this site’s endpoints only.
Impact PHP → Google: OAuth token endpoints; YouTube Data API channels.list?mine=true for channel id/title; Analytics API reports as configured presets.
Google → DB: each report response (columnHeaders + rows) is persisted in impact_yt_analytics_fetch (raw JSON + headers + request params) and impact_yt_analytics_report_row (cells_json: one object per row, keys = API column names).
Reference: Authorization, Channel reports.
Connection status
Fetch analytics
Runs multiple documented-style queries (time series, country, device, traffic source, top videos, etc.). Queries that are not valid for your channel return HTTP errors and are still logged with ok=0.
Custom report (single query)
Uses the same date fields as above. Parameters are restricted to safe patterns; invalid dimension/metric pairs still return API errors and are saved with ok=0. See channel reports.
Stored fetches
| ID | Preset | HTTP | OK | Rows | Created |
|---|
What can be fetched & stored?
- Metrics such as views, watch time, likes, comments, shares, subscribers gained/lost — and optionally estimated revenue / CPM when the channel and scopes allow it.
- Dimensions such as day, country, device type, traffic source, video id, live vs on demand — each preset uses a valid-style combination; unsupported combos are skipped in success terms but saved as failed fetches for debugging.
- Database use — join on
impact_yt_analytics_fetch.id→impact_yt_analytics_report_row.fetch_id; parsecells_jsonin SQL (MySQLJSON_EXTRACT) or in your app; keepresponse_rawfor auditing and re-parsing if Google adds columns.