chain_id我正在尝试使用 gtag方法为 GA4 设置一个自定义维度set。我还在custom_map配置中添加了一个属性,但我什至不确定这是否有必要。问题是,chain_id正如您在 GA 调试器的控制台输出中看到的那样,它永远不会与事件一起发送。
不太确定我在这里缺少什么,但我认为chain_id的值Test chain id应该出现在事件参数中。
document.getElementById("another").addEventListener("click", function(event) {
gtag("event", "Button click");
});Run Code Online (Sandbox Code Playgroud)
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<my-ga-id>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("set", {
chain_id: "Test chain id"
});
gtag("config", "<my-ga-id>", {
debug_mode: true,
custom_map: {
dimension1: 'chain_id'
}
});
</script>
<button id="another">Another click</button>Run Code Online (Sandbox Code Playgroud)
javascript google-analytics custom-dimensions google-analytics-4