【问题标题】:Getting Lifetime Values from Google Analytics API从 Google Analytics API 获取生命周期价值
【发布时间】:2016-05-01 07:55:54
【问题描述】:

Google Analytics API 文档显示,对于获取生命周期值,不应指定日期范围。但是当我提出这样的请求(没有日期范围)时,它会返回空维度和指标结果。但是当我使用日期范围时,它会返回该日期范围的维度和指标值。

以下是 API documentation 的摘录:

不应为同类群组或生命周期值指定日期范围 请求。

例如,如果我提出没有日期范围的请求,如下所示:

{
 "reportRequests": [
  {
   "viewId": "XXXXXXXXX",
   "dimensions": [
    {
     "name": "ga:date"
    },
    {
     "name": "ga:eventLabel"
    }
   ],
   "metrics": [
    {
     "expression": "ga:totalEvents"
    }
   ]
  }
 ]
}

我收到以下回复:

{
 "reports": [
  {
   "columnHeader": {
    "dimensions": [
     "ga:date",
     "ga:eventLabel"
    ],
    "metricHeader": {
     "metricHeaderEntries": [
      {
       "name": "ga:totalEvents",
       "type": "INTEGER"
      }
     ]
    }
   },
   "data": {
    "totals": [
     {
      "values": [
       "0"
      ]
     }
    ]
   }
  }
 ]
}

但是,如果我包含日期范围,

{
 "reportRequests": [
  {
   "viewId": "XXXXXXXX",
   "dimensions": [
    {
     "name": "ga:date"
    },
    {
     "name": "ga:eventLabel"
    }
   ],
   "metrics": [
    {
     "expression": "ga:totalEvents"
    }
   ],
   "dateRanges": [
    {
     "startDate": "2016-01-01",
     "endDate": "2016-04-30"
    }
   ]
  }
 ]
}

我收到以下回复:

{
 "reports": [
  {
   "columnHeader": {
    "dimensions": [
     "ga:date",
     "ga:eventLabel"
    ],
    "metricHeader": {
     "metricHeaderEntries": [
      {
       "name": "ga:totalEvents",
       "type": "INTEGER"
      }
     ]
    }
   },
   "data": {
    "rows": [
     {
      "dimensions": [
       "20160412",
       "http://mytestblog.com/"
      ],
      "metrics": [
       {
        "values": [
         "1"
        ]
       }
      ]
     },
     {
      "dimensions": [
       "20160412",
       "http://mytestblog.com/2016/04/first-post.html"
      ],
      "metrics": [
       {
        "values": [
         "3"
        ]
       }
      ]
     },
     {
      "dimensions": [
       "20160419",
       "http://mytestblog.com/"
      ],
      "metrics": [
       {
        "values": [
         "4"
        ]
       }
      ]
     },
     {
      "dimensions": [
       "20160419",
       "http://mytestblog.com/2016/04/fourth.html"
      ],
      "metrics": [
       {
        "values": [
         "13"
        ]
       }
      ]
     }
    ],
    "totals": [
     {
      "values": [
       "21"
      ]
     }
    ],
    "rowCount": 4,
    "minimums": [
     {
      "values": [
       "1"
      ]
     }
    ],
    "maximums": [
     {
      "values": [
       "13"
      ]
     }
    ]
   }
  }
 ]
}

为什么即使在文档中指定,我也必须在 ReportRequest 中指定日期范围才能获取值?我在这里误解了 Lifetime values 的含义吗?

【问题讨论】:

    标签: google-analytics-api google-analytics-firebase


    【解决方案1】:

    reportRequest 对象应具有dateRanges 的值或cohortGroup 的定义值。当您省略这两个请求时,假定startDate7daysAgoendDateyesterday 的默认值。

    文档的正确解释是 reportRequest 不应该为队列和 LTV 请求定义 dateRange。但为了提出同类群组或生命周期价值请求,您必须添加同类群组定义。对于生命周期价值请求,除了将 lifetimeValue 字段设置为 true 之外,同类群组定义还应具有特定的 dateRange

    POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
    {
        "reportRequests": [
        {
            "viewId": "XXXX",
            "dimensions": [
                {"name": "ga:cohort" },
                {"name": "ga:cohortNthWeek" }],
            "metrics": [
                {"expression": "ga:cohortTotalUsersWithLifetimeCriteria"},
                {"expression": "ga:cohortRevenuePerUser"}
            ],
            "cohortGroup": {
                "cohorts": [{
                    "name": "cohort 1",
                    "type": "FIRST_VISIT_DATE",
                    "dateRange": {
                        "startDate": "2015-08-01",
                        "endDate": "2015-09-01"
                    }
                },
                {
                    "name": "cohort 2",
                    "type": "FIRST_VISIT_DATE",
                    "dateRange": {
                        "startDate": "2015-07-01",
                        "end_date": "2015-08-01"
                    }
                }],
               "lifetimeValue": True
            }
        }]
      }
    

    【讨论】:

    • 感谢@Matt 的评论。似乎有 Lifetime Value Report 与 CohortGroup 分开。此报告仅适用于App Views。此外,默认情况下,在不指定日期范围的情况下,似乎获取了当前月份的数据(至少对于 webview)
    • 澄清一下,为了提出生命周期价值请求,您必须定义 cohortGroup 并将 lifetimeValue 字段设置为 True
    猜你喜欢
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2015-10-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    相关资源
    最近更新 更多