Google Analytics报告Api v4报告请求响应具有行数但空行元素

时间:2017-09-07 14:12:41

标签: google-analytics google-analytics-api google-analytics-v4

我有980多个viewids我每天都在运行报告请求。它们被加载到rs db中。

我有报告请求为所有ID执行最初3个月的回填运行。

在检查数据时,我们注意到有些ID似乎没有为它们运行回填。我查看了日志,并没有从api收到任何错误。

我开始为单个viewid运行单个报告请求,并在响应中返回行值。

我在我们的应用程序中添加了更多日志记录,因为我认为我可能只是没有抓住错误。

对于前850个左右,我会回到预期的状态。过去3个月的数据,如果有的话。

最后100多个ID我已经获得了具有行数,最大值,最小值和总数不是0以及空行元素的视图的响应。那就是我现在所处的位置。不确定这是否是api的bug或功能。无法在任何地方找到任何类似问题。

一些注释:

我们每天在一台服务器上同时运行12个报告请求。在Api控制台中,我们每天看到大约12,000个请求。它是发出请求的节点应用程序。我们在处理所有viewid的每日报告请求时没有发现这种情况,我们没有达到50,000个请求的每日限制,我们确实已经实现了指数退出,当我们遇到速率限制错误时我们正在重试

我们的一个报告请求示例:

`{
"reportRequests": [
{
"dateRanges": [
{
  "startDate": "2017-06-01",
   "endDate" : "2017-09-01"
}
],
"metrics": [
  {"expression": "ga:entrances"}, 
  {"expression": "ga:goalAbandonsAll"}, 
  {"expression": "ga:users"}, 
  {"expression": "ga:sessions"}, 
  {"expression": "ga:bounces"}, 
  {"expression": "ga:goalStartsAll"}, 
  {"expression": "ga:sessionDuration"}, 
  {"expression": "ga:goalValueAll"}, 
  {"expression": "ga:pageviews"}, 
  {"expression": "ga:timeOnPage"}
],
"pageSize": 10000, 
"includeEmptyRows": true, 
"dimensions": [
  {"name": "ga:adwordsCreativeID"},
  {"name": "ga:adSlot"},
  {"name": "ga:adTargetingType"},
  {"name": "ga:adDistributionNetwork"},
  {"name": "ga:adKeywordMatchType"},
  {"name": "ga:hour"},
  {"name": "ga:date"}
],
"samplingLevel": "LARGE",
"viewId": "123456789"
}
]
}`

我们看到奇怪的回应:

`{
"columnHeader":{
"dimensions":[
"ga:adwordsCreativeID",
"ga:adSlot",
"ga:adTargetingType",
"ga:adDistributionNetwork",
"ga:adKeywordMatchType",
"ga:hour",
"ga:date"
],
"metricHeader":{
"metricHeaderEntries":[
{"name":"ga:entrances","type":"INTEGER"},{"name":"ga:goalAbandonsAll","type":"INTEGER"},{"name":"ga:users","type":"INTEGER"},{"name":"ga:sessions","type":"INTEGER"},{"name":"ga:bounces","type":"INTEGER"},{"name":"ga:goalStartsAll","type":"INTEGER"},{"name":"ga:sessionDuration","type":"TIME"},{"name":"ga:goalValueAll","type":"CURRENCY"},{"name":"ga:pageviews","type":"INTEGER"},{"name":"ga:timeOnPage","type":"TIME"}
]
}},
"data":{
"totals":[
{"values":["1235","0","1245","1235","1091","0","63517.0","0.0","1450","63515.0"]}
],
"rowCount":602,
"minimums":[
{"values":["0","0","1","0","0","0","0.0","0.0","1","0.0"]}
],
"maximums":[
{"values":["10","0","10","10","8","0","4920.0","0.0","16","4909.0"]}
],
"rows":[]}`

1 个答案:

答案 0 :(得分:0)

您找到有关此问题的更多信息吗?看来,如果您收到“空”报告(仅包含最小值/最大值/总数)作为Google Analytics(分析)的响应,则发送新请求将解决此问题。 检查report ['data] ['rows']是一种识别报告是否为“空”的方法。

response = [...]
while self.is_response_empty(response):
    response = [...]

def is_response_empty(self, response):
    for report in response.get('reports', []):
        try:
            report['data']['rows']
            return False
        except:
            return True