我正在尝试使用“set”命令将数据添加到我通过 javascript 在 GA4 中发送的每个事件:
https://developers.google.com/tag-platform/gtagjs/reference#set
从这些文档来看,它似乎与 Serilog Enrichment 类似,但它似乎不起作用,而且我没有看到这些数据。
我正在使用 localhost + Google Analytics 调试器 chrome 扩展。然后,在“分析”>“配置”>“调试视图”中,我看到自定义事件“hello-world”和属性“test”,但没有看到通过“set”命令添加的数据。
GA调试视图
我使用 set 命令进行了 2 次调用 - 第一个是有效的“user_id”属性。这一定是一个特殊情况,因为 GA 的处理方式有所不同。第二个是针对不起作用的自定义对象。
控制台显示两个 set 命令调用的一些输出,但没有任何信息告诉我某些操作已成功或失败
<!DOCTYPE html>
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-SOMECODE"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
gtag('js', new Date());
// Set enrichment properties for every event "on this page"
// https://developers.google.com/tag-platform/gtagjs/reference#set
gtag('set', {
'foo': 'bar',
});
// Set the measurement id
// https://developers.google.com/analytics/devguides/collection/gtagjs/setting-values
gtag('config', 'G-SOMECODE');
//Set the GA4 user_id and keep it set for all events
gtag('set', {
'user_id': 'a24b935c-03cd-47f0-af68-c60a68b31303'
});
gtag('event', 'hello-world', {
'test': true
});
</script>
<title>Html Delivery</title>
<script type="text/javascript">
function myFunction() {
// Event with nested data test. It doesnt seem to display nicely
gtag('event', 'button-click-nested', {
'data': {
'type': 'nextButton'
}
});
gtag('event', 'button-click', {
'type': 'nextButton'
});
}
function LinkFunction() {
console.log("link click");
gtag('event', 'link click', {
'type': 'link'
});
}
</script>
</head>
<body>
<button onclick="myFunction()">Next</button>
<a id="myLink" href="#" title="Click to do something" onclick="LinkFunction()">link text</a>
</body>
</html>
我尝试将调用移至配置命令的上方/下方,但这也没有什么区别。
有一个类似的问题,但我的代表不允许我对此发表评论,看看情况是否仍然如此。接受的答案并没有真正帮助我,因为我希望能够以这种方式添加任何任意数据。
我尝试在 GA 中为此设置一个自定义指标(我没有使用 GTM),但仍然如此。没有数据通过。
难道这行不通吗?
我们在这里经历了同样的问题:Google Analytics 自定义维度不起作用:gtag set() 方法问题tl;dr: 不要使用 set,它是用于 GTM 的。 gtag 文档具有误导性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)