无法从Google Analytics(分析)中检索超过1万条记录 [英] Unable to retrieve more than 10k records from Google Analytics

查看:93
本文介绍了无法从Google Analytics(分析)中检索超过1万条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了Windows控制台应用程序,该应用程序提取Google Analytics(分析)数据并将其写入.CSV文件.在Google Analytics Query Explorer中查询特定日期的数据时,它显示:-您的查询匹配96782个结果...".

I've developed a windows console application which extracts Google Analytics data and writes to .CSV file. When queried for data of particular date on Google Analytics Query Explorer, it displayed:- "Your query matched 96782 results...".

问题是当我使用应用程序查询同一日期的数据时,默认情况下,它仅返回1000条记录,而当我进行设置时

The problem is when when i query for the data of same date using application, by default it returns only 1000 records and when I set

DataResource.GaResource.GetRequest objRequest.MaxResult超过10k,那么它给了我最多10k条记录.

DataResource.GaResource.GetRequest objRequest.MaxResult more than 10k, then it gives me max to max 10k records.

有什么方法可以获取超过10k的记录.

Is there any way to get records more than 10k.

推荐答案

所以我所做的是,我将Request.MaxResult = 10000设置为Response.ItemsPerPage =10000.至关重要的作用是由具有分页机制的Request.StartIndex扮演的.例如在第一个循环中,我们将得到1-10000行,然后是10001-20000 .... 20001-30000,依此类推.

So what i did is, I set Request.MaxResult = 10000 and Response.ItemsPerPage = 10000. The vital role is played by Request.StartIndex which has pagination mechanism e.g. in 1st loop we'll get 1-10000 rows then 10001-20000....20001-30000 and so on.

在循环下,对特定日期的数据的请求最初设置为Request.StartIndex = 1,然后在行数达到第10000行后立即连续增加到MaxResult + 1,例如:- Request.StartIndex = 1,然后是10001,然后是20001 .... 30001 ... 40001,依此类推,直到Response.Rows == null.

Under loop, request to data of a particular day initially is set to Request.StartIndex = 1 and then consecutively increases to MaxResult + 1 as soon as row count reaches 10000th row e.g.:- Request.StartIndex = 1 then 10001 then 20001....30001...40001 and so on untill Response.Rows == null.

这是我的代码:-

            StringBuilder sbrCSVData = new StringBuilder();
            int intStartIndex = 1;
            int intIndexCnt = 0;
            int intMaxRecords = 10000;

            AnalyticsService objAnaSrv = new AnalyticsService(objInit);
            string metrics = "ga:visitors,ga:visits,ga:visitBounceRate,ga:pageviews,ga:pageviewsPerVisit,ga:uniquePageviews,ga:avgTimeOnPage,ga:exits,ga:avgPageLoadTime,ga:goal1ConversionRate";
            DataResource.GaResource.GetRequest objRequest = objAnaSrv.Data.Ga.Get(strProfId, startDate,endDate, metrics);
            objRequest.Dimensions = "ga:visitCount,ga:browser,ga:browserVersion,ga:IsMobile,ga:screenResolution,ga:date,ga:hour";
            objRequest.MaxResults = 10000;

            while (true)
            {
                objRequest.StartIndex = intStartIndex;
                GaData objResponse = objRequest.Fetch();
                objResponse.ItemsPerPage = intMaxRecords;

                  if (objResponse.Rows != null)
                {
                    intIndexCnt++;
                    for (int intRows = 0; intRows < objResponse.Rows.Count; intRows++)
                    {
                        IList<string> lstRow = objResponse.Rows[intRows];
                        for (int intCols = 0; intCols <= lstRow.Count - 1; intCols++)
                        {
                            strRowData += lstRow[intCols].ToString() + "|";
                        }
                        strRowData = strRowData.Remove(strRowData.Length - 1, 1);
                        sbrCSVData.Append(strRowData + "\r\n");
                        strRowData = "";
                    }
                    intStartIndex = intIndexCnt * intMaxRecords + 1;
                }
                else break;
            }

这篇关于无法从Google Analytics(分析)中检索超过1万条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆