同一网页上有多个 Google 个 Google Analytics(分析)gtag 跟踪 ID
Multiple Google Analytics gtag tracking IDs on same page
我的 Google Analytics 帐户中有两个 属性 跟踪 ID 用于同一网站。我基本上想将同一组数据插入到两个 properties/views 中。目前,这是我在网站上设置它的方式:
<!-- 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>
但是,我开始意识到这实际上并没有正常工作。我相信正确的解决方案是这个(两组脚本标签,每个 属性),但我不是 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>
你在第一个例子中做对了。
这是在页面上声明多个跟踪器的正确方法。
gtag('config', 'UA-XXXXXXXX-1');
gtag('config', 'UA-XXXXXXXX-3');
或许可以提供一些无效的示例。
在测试我问题中的解决方案后,我可以确认这是解决此问题的正确方法:
<!-- 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>
我的 Google Analytics 帐户中有两个 属性 跟踪 ID 用于同一网站。我基本上想将同一组数据插入到两个 properties/views 中。目前,这是我在网站上设置它的方式:
<!-- 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>
但是,我开始意识到这实际上并没有正常工作。我相信正确的解决方案是这个(两组脚本标签,每个 属性),但我不是 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>
你在第一个例子中做对了。 这是在页面上声明多个跟踪器的正确方法。
gtag('config', 'UA-XXXXXXXX-1');
gtag('config', 'UA-XXXXXXXX-3');
或许可以提供一些无效的示例。
在测试我问题中的解决方案后,我可以确认这是解决此问题的正确方法:
<!-- 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>