无法从谷歌Analytics(分析)retreive 10K以上的记录 [英] Unable to retreive more than 10k records from Google Analytics

查看:124
本文介绍了无法从谷歌Analytics(分析)retreive 10K以上的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了提取谷歌Analytics的数据,并写入到.csv文件Windows控制台应用程序。当查询在谷歌Analytics(分析)查询浏览特定日期的数据,它显示: - 您的查询匹配的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.

下面是我的代码: -

Here's my code:-

            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;
            }

这篇关于无法从谷歌Analytics(分析)retreive 10K以上的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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