YouTube Analytics API结束屏幕报告,如何确定结束屏幕元素?

时间:2017-09-26 18:34:30

标签: youtube-api

对于“结束屏幕”报告,如何确定每条记录上end_screen_element_id代表哪个目标?

例如:在我的频道上,假设我设置了“视频1”,其中包含两个视频结束屏幕元素“视频2”和“视频3”。我想知道“视频1”结尾处有多少次点击去了“视频2”,有多少人去了“视频3”。

此报告返回的数据为我提供了一个video_id字段,用于指示观看了哪个视频,以及一个end_screen_element_clicks字段,表示观看者点击进入结束屏幕视频的次数...

...但是,观众点击进入的视频的唯一标识符是end_screen_element_id字段,它看起来像一个GUID,显然以某种方式指向完整的结束屏幕元素定义,因此可能是该定义所代表的视频。

我无法找到任何报告或其他API调用来获取有关end_screen_element_id字段的详细信息,尤其是它所代表的视频。

如何使用该字段或以其他方式确定观众点击的最终屏幕视频?

更多信息

返回的数据如下所示: Data returned in the End Screens report

这是一个截图,可能有助于解释我正在尝试处理的数据:YouTube Analytics screen shot

以下C#代码演示了如何请求报告:

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
    ClientId = CLIENT_ID,
    ClientSecret = CLIENT_SECRET
},
    new[] {  YouTubeReportingService.Scope.YtAnalyticsReadonly },
    "user",
    CancellationToken.None,
    new FileDataStore("Drive.Auth.Store")).Result;

YouTubeReportingService reportingService = new YouTubeReportingService(new BaseClientService.Initializer
{
    HttpClientInitializer = credential,
    ApplicationName = APPLICATION_NAME
});

// Submit a report job to obtain the latest End Screen statistics.
Job channelEndScreenJob = new Job();
channelEndScreenJob.ReportTypeId = "channel_end_screens_a1";
channelEndScreenJob.Name = JOB_NAME;

Job createdJob = 
reportingService.Jobs.Create(channelEndScreenJob).Execute();

单独的服务检索报告,如下所示:

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
    ClientId = CLIENT_ID,
    ClientSecret = CLIENT_SECRET
},
    new[] {  YouTubeReportingService.Scope.YtAnalyticsReadonly },
    "user",
    CancellationToken.None,
    new FileDataStore("Drive.Auth.Store")).Result;

YouTubeReportingService reportingService = new YouTubeReportingService(new BaseClientService.Initializer
{
    HttpClientInitializer = credential,
    ApplicationName = APPLICATION_NAME
});

// Retrieve data from jobs that were previously submitted.
ListJobsResponse jobList = reportingService.Jobs.List().Execute();

if (jobList.Jobs != null)
{
    foreach (Job job in jobList.Jobs)
    {
        ListReportsResponse reportList = reportingService.Jobs.Reports.List(job.Id).Execute();

        if (reportList.Reports != null)
        {
            foreach (Report report in reportList.Reports)
            {
                MediaResource.DownloadRequest getRequest = reportingService.Media.Download("");

                // Download the report data.
                using (MemoryStream stream = new MemoryStream())
                {
                    getRequest.MediaDownloader.Download(report.DownloadUrl, stream);
                    stream.Flush();
                    stream.Position = 0;

                    using (StreamReader reader = new StreamReader(stream))
                    {
                        // Parse report...
                        DataTable parsedReport = ReportToDataTable(reader.ReadToEnd());

                        // ...and get data on videos watched and videos clicked to.
                        foreach (DataRow row in parsedReport.Rows)
                        {
                            string videoWatched = row["video_id"].ToString();
                            string videoClickedToFromEndScreen = **WHAT???**
                        }
                    }
                }
            }
        }
    }
}

0 个答案:

没有答案