[英]Multiple Google Analytics gtag tracking IDs on same page
I have two property tracking IDs in my Google Analytics account for the same website.我的 Google Analytics(分析)帐户中有两个用于同一网站的资产跟踪 ID。 I basically want to have the same set of data inserted into both properties/views.
我基本上希望将相同的数据集插入到两个属性/视图中。 Currently, this is how I have it set up on the site:
目前,这是我在网站上设置的方式:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
gtag('config', 'UA-XXXXXXXX-3');
</script>
However, I have come to realize this is not actually working correctly.但是,我已经意识到这实际上并不能正常工作。 I believe the proper solution to this is this (two sets of script tags, one for each property), but I am not 100% sure:
我相信正确的解决方案是这样(两组脚本标签,每个属性一组),但我不是 100% 确定:
<!-- Global site tag (gtag.js) 1 - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
</script>
<!-- Global site tag (gtag.js) 2 - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-3');
</script>
After testing the solution in my question, I can confirm that is the proper way to solve this:在我的问题中测试解决方案后,我可以确认这是解决此问题的正确方法:
<!-- Global site tag (gtag.js) 1 - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
</script>
<!-- Global site tag (gtag.js) 2 - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-3');
</script>
You had it correct in your first example.您在第一个示例中是正确的。 This is the correct way to declare multiple trackers on the page.
这是在页面上声明多个跟踪器的正确方法。
gtag('config', 'UA-XXXXXXXX-1');
gtag('config', 'UA-XXXXXXXX-3');
Maybe provide some examples on what isn't working.也许提供一些关于什么不起作用的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.