简体   繁体   English

通过 API 阅读 GA4 (Google Analytics 4) 会话

[英]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请求正文中指定metricsdateRanges 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.

相关问题 Google Analytics Data API (GA4) - item.variant 维度? - Google Analytics Data API (GA4) - item.variant dimension? Google Analytics Embed API 是否支持新的 GA4 属性? - Does the Google Analytics Embed API support the new GA4 properties? Google Analytics 数据上的自定义维度 API (GA4) Python - Custom dimensions on Google Analytics Data API (GA4) Python GA4 | 谷歌分析管理员 API | 应用脚本 - GA4 | Google Analytics Admin API | Apps Script Google Analytics Data API(GA4) - bounceRate 指标缺失 - Google Analytics Data API(GA4) - bounceRate metric missing 在 Delphi 10.4.2 中使用 Google Analytics GA4 - Working with Google Analytics GA4 in Delphi 10.4.2 Google Analytics 报告 API V3/V4 与 Google Analytics 4 (GA4) 的兼容性 - Google Analytics Reporting API V3/V4 compatibility with Google Analytics 4 (GA4) 获取特定事件计数,Google Analytics 数据 API (GA4) 中的 Google Analytics 4 - Get spesific event count, Google Analytics 4 in Google Analytics Data API (GA4) Google Analytics GA4 用户问题 - Google Analytics GA4 User Problems 使用 Google Analytics 数据 API 在 GA4 属性之间复制 Google Analytics 自定义定义/维度? - Copy Google Analytics custom definitions/dimensions between GA4 properties with the Google Analytics Data API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM