Google Analytics用户ID报告维度和度量



我需要用每个用户的用户ID报告数据填充我的数据库(我所指的报告可以在Google Analytics>Reports>User Explorer中找到(>单击用户ID((。

我正在查看文档,但似乎找不到任何可以用来实现这一目标的维度或指标:https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/?authuser=1

我希望我有一些代码示例,但是另一种方法是运行这个脚本(为了简单起见,我不会在这里包括所有其他函数(:

def get_user_Activity(analytics, VIEW_ID, user_id, start_date, end_date):
# Use the Analytics Service Object to query the Analytics Reporting API V4.
return analytics.userActivity().search(
body={
"viewId": VIEW_ID,
"user": {
"type": "USER_ID",
"userId": user_id
},
"dateRange": {
"startDate": start_date,
"endDate": end_date
},
"activityTypes": [
"PAGEVIEW", "EVENT"
]
}
).execute()

这将为每个用户id生成这个字典:

{'sessions': [{'sessionId': '1579xxxx', 
'deviceCategory': 'desktop', 
'platform': 'Windows', 
'dataSource': 'web', 
'activiti es': [{'activityTime': '2020-01-22T12:48:20.971410Z', 
source': '(direct)', 
'medium': '(none)', 
'channelGrouping': 'Direct', 
'campaign': '(not set)', 
'keyword': '(not set)', 
'hostname': 'example.com', 
'landingPagePath': '/somelandingpage', 
'activityType': 'PAGEVIEW', 
'customDimension': [{'index': 1}], 
'pageview': {'pagePath': '/some/page', 'pageTitle': 'SOME Title'}}, 
{'activityTime': '2020-01-22T12:48:20.970754Z', 
'source': '(direct)', 
'medium': '(none)', 
'channelGrouping': 'Direct', 
'campaign': '(not set)', 
'keyword': '(not set)', 
'hostname': 'example.com',
'landingPagePath': '/somelandingpage', 
'activityType': 'PAGEVIEW', 
'customDimension': [{'index': 1}], 
'pageview': {'pagePath': '/some/other/path', 'pageTitle': 'SomeTitle'}},...
..................
etc ..............

这种方法的问题是,我必须计算我感兴趣的大多数指标,相反,我更喜欢只收集指标并填充数据库。

如果所需的";ga:尺寸";以及";ga:度量";如果能提供,我们将不胜感激。

在Google Core reporting API中没有内置的对userId级别报告的支持,因此您必须根据活动API响应中的可用内容计算所有必要的指标。唯一的选择是使用与用户ID具有相同值的用户级自定义维度。但是,只有提前实现了此跟踪,这才有效。

最新更新