[英]Read GA4 (Google Analytics 4) sessions via API
Our app has access & refresh token for our customers and we have permissions to read their Google analytics accounts.我们的应用程序为我们的客户提供访问和刷新令牌,并且我们有权读取他们的 Google 分析帐户。 We noticed that we can not access data of GA4 properties.我们注意到我们无法访问 GA4 属性的数据。
I managed to list GA4 properties:我设法列出了 GA4 属性:
GET https://analyticsadmin.googleapis.com/v1alpha/accountSummaries
headers: Authorization: Bearer @TOKEN
However I can not find a way to retrieve eg sessions in last 30 days for GA4 properties (which are returned in the response above).但是,我无法找到一种方法来检索例如过去 30 天内 GA4 属性的会话(在上面的响应中返回)。 It seems like something like request below should do the trick:看起来像下面的请求应该可以解决问题:
POST https://analyticsdata.googleapis.com/v1beta/{property=properties/*}:runReport
headers: Authorization: Bearer @TOKEN
But it doesn't work.但它不起作用。 What am I missing?我错过了什么? Even hints would be welcome!即使是提示也会受到欢迎!
You need to specify the metrics
and dateRanges
in the body of the POST
request to :runReport
method.您需要在:runReport
方法的POST
请求正文中指定metrics
和dateRanges
。 This is an example HTTP Post Report Request & Response .这是一个示例HTTP 发布报告请求和响应。 This API Quickstart Guide discusses specifying the request body in a request.json
, enabling the Data API, & configuring authentication.本API 快速入门指南讨论了在请求中指定请求主体request.json
,启用数据 API 和配置身份验证。
For this report, your request should be similar to the following.对于此报告,您的请求应类似于以下内容。 GA4_PROPERTY_ID
should be replaced with your numeric Google Analytics 4 Property ID . GA4_PROPERTY_ID
应替换为您的数字Google Analytics 4 Property ID 。
POST https://analyticsdata.googleapis.com/v1beta/properties/GA4_PROPERTY_ID:runReport
{
"dateRanges": [{ "startDate": "29daysAgo", "endDate": "today" }],
"metrics": [{ "name": "sessions" }]
}
For this report, the response will be similar to the following:对于此报告,响应将类似于以下内容:
{
"metricHeaders": [
{
"name": "sessions",
"type": "TYPE_INTEGER"
}
],
"rows": [
{
"metricValues": [
{
"value": "1495"
}
]
}
],
"rowCount": 1,
"metadata": {
"currencyCode": "USD",
"timeZone": "America/Los_Angeles"
},
"kind": "analyticsData#runReport"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.