Google Analytics(分析)在报告API中获取用户ID

我想获取用户ID,该ID可在用户资源管理器报告google Analytics(分析)中找到。 我在下面的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错误。 即使我复制了在Google Analytics(分析)中的用户浏览器报告仪表板中可见的用户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()

响应

  

回溯(最近一次通话最后一次):文件“ ga_session_data.py”,行   192,在       ga.main()文件“ ga_session_data.py”,第178行,位于主目录中       result = analytics.useractivity()。search(body = body).execute()文件“ env / lib / python3.6 / site-packages / googleapiclient / _helpers.py”,   第130行,位于positional_wrapper中       返回包装的(* args,** kwargs)文件“ env / lib / python3.6 / site-packages / googleapiclient / http.py”,   执行中的第856行       引发HttpError(resp,content,uri = self.uri)googleapiclient.errors.HttpError:https://analyticsreporting.googleapis.com/v4/useractivity:search?alt=json   返回了“ CLIENT_ID:XXXXXXXX找不到。”

linian000 回答:Google Analytics(分析)在报告API中获取用户ID

用户ID和客户端ID是Google Analytics(分析)中两个不同的维度。用户资源管理器报告基于user ID,并且此ID可能与API报告中client Id维度下显示的ga:clientId不同。 要使用基于client 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

本文链接:https://www.f2er.com/3108841.html

大家都在问