Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube Live Analytics (views, total watch time)

Tags:

youtube-api

I need to get metrics (primarily total live views and total/avg live view duration) for YouTube LIVE events. I'm having trouble with both v2 and v3 APIs.

I can schedule and stream through the API fine, and I'd like to pull the analytics as soon as the broadcast ends to roll up some reports.

Question

How can I get total or average live view duration from the v3 API?

Or, how can I properly query the v2 reports API for Live events to get non-zero data back?

More Details On Current Attempts

Here are the types of queries I've tried:

YouTube v3 API:

https://www.googleapis.com/youtube/v3/videos?
    id={live_video_id}&
    part={"statistics,liveStreamingDetails"}&
    access_token={access_token}

{
 "kind": "youtube#videoListResponse",
 "etag": "...",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "...",
   "id": "..",
   "statistics": {
    "viewCount": "38",
    "likeCount": "1",
    "dislikeCount": "0",
    "favoriteCount": "0",
    "commentCount": "0"
   },
   "liveStreamingDetails": {
    "actualStartTime": "2018-10-11T12:01:23.000Z",
    "actualEndTime": "2018-10-11T14:00:12.000Z",
    "scheduledStartTime": "2018-10-11T12:00:00.000Z",
    "scheduledEndTime": "2018-10-11T14:00:00.000Z"
   }
  }
 ]
}

I can get statistics.viewCount count here, but there's no way to get the avg/total time watched.

YouTube v2 Reports API:

https://youtubeanalytics.googleapis.com/v2/reports?
    startDate={"2017-01-01"}&
    endDate={time.Now().Add(24*time.Hour).Format("YYYY-MM-DD")}&
    filters={"video==" + live_video_id}&
    metrics={"views,estimatedMinutesWatched"}&
    ids={"channel==MINE"}&
    access_token={accessToken}

{
  "kind": "youtubeAnalytics#resultTable",
  "columnHeaders": [
    {
      "name": "views",
      "columnType": "METRIC",
      "dataType": "INTEGER"
    },
    {
      "name": "estimatedMinutesWatched",
      "columnType": "METRIC",
      "dataType": "INTEGER"
    }
  ],
  "rows": [
    [
      0,
      0
    ]
  ]
}

This query would seem to give the metrics I need, but it's all 0s, even when v3 returns non-zero views.

like image 694
Mike Griffith Avatar asked Oct 29 '22 03:10

Mike Griffith


1 Answers

TL;DR YouTube Reports API v2 doesn't update the metrics quite often for less popular live streams.

This is how I reached this conclusion...

I fetched the views, estimatedMinutesWatched of an old video from my channel. While both these APIs worked, the view count returned by the YouTube Reports API v2 was not accurate and was lagging behind the YouTube Data API v3.

Next, I ran a Livestream (unlisted) and engaged on the stream with a few other accounts. None of these engagements (like, subscribe, views) was shown in the Reports API v2 nor in YouTube Studio Analytics. This proves that the "rows": [[0,0]] returned by YouTube Reports API v2 is completely normal. But surprisingly, the Data API v3 did return the correct metrics as you pointed out.

For live streams with large audience and engagement, the Reports API may work perfectly fine.

Since the Data API doesn't provide watch times of any sort, your best bet would be to use both these APIs in conjunction, Data API v3 to fetch the basic metrics like views, likes,.. and the Reports API v2 for more sophisticated metrics.

Tip: If you are interested in displaying the live stream metrics later on, you can use the dimension=liveOrOnDemand parameter and filter the metrics to the LIVE stream alone.

like image 105
Shan Eapen Koshy Avatar answered Jan 02 '23 19:01

Shan Eapen Koshy