使用Google Analytics Data API按事件名及用户名统计事件数的指标维度咨询
针对GA4 Data API事件统计的正确配置
所需维度与指标
维度
eventName:用于按事件名称分组,对应需求中的event_nameuserProperty.username:引用user_properties中的自定义用户名属性,GA4 Data API中自定义用户属性必须以userProperty.为前缀
你之前遇到的
user_id无效错误,是因为GA4 Data API中没有名为user_id的维度:
- 如果是系统默认用户ID,对应维度为
userId(驼峰命名)- 如果是自定义的user_id属性,同样需要用
userProperty.user_id格式引用
指标
eventCount:GA4 Data API中专门用于统计事件发生次数的核心指标
请求体示例
{ "dimensions": [ {"name": "eventName"}, {"name": "userProperty.username"} ], "metrics": [ {"name": "eventCount"} ] }
注意事项
- 确保
username用户属性已在GA4后台完成配置,且前端/后端正常将该属性发送至GA4,否则API返回的该维度值会为空 - GA4 Data API的字段命名严格遵循驼峰规则,请勿使用下划线分隔的命名方式
内容的提问来源于stack exchange,提问作者elaamrani
相关产品推荐
相关产品推荐

