admin管理员组文章数量:1289876
I'm trying to set up a custom dimension for GA4 called chain_id
using the gtag set
method. I've also added a custom_map
property in the config but I'm not even sure if that is necessary. The issue is that the chain_id
is never being sent with the event as you can see in the console output from the GA debugger.
Not really sure what I'm missing here but I think that chain_id
with the value of Test chain id
should be present in event parameters.
document.getElementById("another").addEventListener("click", function(event) {
gtag("event", "Button click");
});
<!-- Google tag (gtag.js) -->
<script async src="=<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>
I'm trying to set up a custom dimension for GA4 called chain_id
using the gtag set
method. I've also added a custom_map
property in the config but I'm not even sure if that is necessary. The issue is that the chain_id
is never being sent with the event as you can see in the console output from the GA debugger.
Not really sure what I'm missing here but I think that chain_id
with the value of Test chain id
should be present in event parameters.
document.getElementById("another").addEventListener("click", function(event) {
gtag("event", "Button click");
});
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager./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>
Share
Improve this question
edited Mar 2, 2023 at 17:20
BNazaruk
8,1263 gold badges21 silver badges39 bronze badges
asked Sep 27, 2022 at 15:28
Nenad VracarNenad Vracar
122k16 gold badges160 silver badges183 bronze badges
2 Answers
Reset to default 8 +200gtag set doesn't work. Well or at least it doesn't work as one would expect it to work. Google's documentation is off. Set changes the DL for GTM's benefit. It's not very useful for setting properties. But you have similar options.
You can just set the params within the event call itself, like so:
gtag("event", "Button click", {chain_id: "test id"});
The picture is from this page's console.
- You also can set the eps with the config and they will persist:
Note that Google made another sneak update for ignoring configs that are issued after the initial config has been used. So if you're trying to change persistent event parameters for all subsequent events by issuing a config and gtag.js just ignores it, then give this answer a read: can GA4 custom dimensions be updated after the initial 'config' call?
Overall, please consider using GTM. Or any other TMS. It makes tracking a lot easier to implement, manage, scale and support. Tracking directly with gtag.js only really makes sense when you have to do just a little bit of tracking and you don't really care much about what real business results this tracking achieves in the longer term.
I am not sure why set
is not working. But maybe you can try to use config
Google Document about it
When we use GTM to do something like this. We will use Field To Set
and it's basically call
gtag('config','{Your GA4 ID}', { 'chain_id': 'Test chain id' });
And this will need some additional code when you call event
gtag('event','click', { 'send_to': '{Your GA4 ID}' });
I think it is worth to try.
本文标签: javascriptGoogle Analytics custom dimension not working gtag set() method issuesStack Overflow
版权声明:本文标题:javascript - Google Analytics custom dimension not working: gtag set() method issues - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741467261a2380383.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论