我正在尝试遵循本指南:https ://developers.google.com/gtagjs/reference/api#set
它表示您可以用来gtag('set', {key: value})将一组值添加到下一个gtag调用中。然而,这不起作用。
因此,这是我为了gtag在应用程序上可用而使用的设置:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('set', 'anonymizeIp', true);
gtag('config', 'my_ga_tracking_id', {
send_page_view: false,
custom_map: {
dimension1: 'a_dimension'
}
});
Run Code Online (Sandbox Code Playgroud)
加载应用程序后,然后执行以下代码:
gtag('set', { a_dimension: 'test' });
gtag('event', 'an_event');
Run Code Online (Sandbox Code Playgroud)
我希望看到发送给 GA 的a_dimension活动附件an_event,但我找不到它。
我缺少什么?
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