gpt4 book ai didi

python - 谷歌分析在报告API中获取用户ID

转载 作者:行者123 更新时间:2023-12-01 06:55:18 25 4
gpt4 key购买 nike

我喜欢获取用户资源管理器报告谷歌分析中可用的用户 ID。我正在使用下面的batchGet来使用ga:clientId获取用户ID列表 https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet

我能够获取客户端 ID,但是当使用以下 API 尝试相同的 ID 时 https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/userActivity/search#request-body

未找到返回 400 错误。即使我复制谷歌分析中用户资源管理器报告仪表板中可见的用户 ID,它仍然返回 400 未找到错误。我是不是做错了什么?

代码片段

analytics = build('analyticsreporting', 'v4', credentials=credentials)
body={
"viewId": VIEW_ID,
"user": {
"type": "USER_ID", # I have tried CLIENT_ID Also
"userId": user_id # For now I have copied the value directly from the user explorer from browser itself for testing.But it didn't worked
}
}
result=analytics.userActivity().search(body=body).execute()

回应

Traceback (most recent call last): File "ga_session_data.py", line 192, in ga.main() File "ga_session_data.py", line 178, in main result=analytics.userActivity().search(body=body).execute() File "env/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper return wrapped(*args, **kwargs) File "env/lib/python3.6/site-packages/googleapiclient/http.py", line 856, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: https://analyticsreporting.googleapis.com/v4/userActivity:search?alt=json returned "CLIENT_ID: XXXXXXXX not found.">

最佳答案

用户 ID 和客户端 ID 是 Google Analytics(分析)中的两个不同维度。用户浏览器报告基于用户 ID,此 ID 可能与 API 报告中 ga:clientId 维度下显示的客户端 ID 不同。要使用基于客户端 ID 值的事件报告,请在事件请求中使用以下对象:

{
"type": "CLIENT_ID",
"userId": "your.value"
}

为了获取用户浏览器报告中出现的特定用户 ID 的数据,请使用以下对象:

{
"type": "USER_ID",
"userId": "your.value"
}

https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/userActivity/search#request-body

关于python - 谷歌分析在报告API中获取用户ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58840416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com