通过Google 4的测量协议,我们可以发送自定义事件(来源)。然而,使用gtag.js Google,GA会自动跟踪几个预定义用户尺寸。
该文件页提到:
只要使用SDK或gtag.js,就不需要编写额外的代码来从移动应用程序和/或网站收集以下用户维度。
然而,我们如何收集这些用户维度(如语言,浏览器,国家)与测量协议?不幸的是,协议参考中没有记录这一点。(我在其他地方也找不到这方面的信息。)
编辑
下面是我要发送的JSON数据的一个示例:
{
"client_id": "xxx",
"timestamp_micros": 1666280202293304,
"events": [
{
"name": "page_view",
"params": {
"event_source": "server",
"page_location": "https://somedomain.com/page2",
"page_referrer": "/page1",
"page_title": "A test page",
"ip_override": "xxx.xxx.xxx.0",
"user_agent": "Mozilla/5.0 (Linux; Android 9; RMX1805) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36",
"debug_mode": false,
"engagement_time_msec": 1,
"session_id": "yyy"
}
}
],
"user_properties": {
"country": {
"value": "US"
},
"device_category": {
"value": "None"
},
"language": {
"value": "en-us"
},
"platform": {
"value": "web"
}
}
}发布于 2022-10-19 21:52:59
现在,在user_properties测量协议有效载荷中有一些关于GA4语法的文档。它与client_id和events定义一起使用。
const queryParams = `?measurement_id=${measurementId}&api_secret=${apiSecret}`;
fetch(`https://www.google-analytics.com/mp/collect${queryParams}`, {
method: "POST",
body: JSON.stringify({
"client_id": clientId,
"user_properties": {
"customer_tier": {
"value": customerTier
}
},
"events": JSON.parse(events)
})
});https://stackoverflow.com/questions/71871458
复制相似问题