Google Analytics JS 示例
Google Analytics JS by Example
我正在尝试让我的 JS 页面将基本指标报告回我的 GA 帐户。然而,Google 文档并没有真正清晰地/一致地阐明如何实现这一点。一方面,您有 analytics.js
片段:
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
但这并没有显示您实际上是如何将 ga
函数与您的 GA account/client ID 联系起来的。
那么您有 this behemoth of JS, but that looks totally different than the first snippet above. So I ask, can someone explain and provide an SSCCE 个所需的 JS 来实际从页面发回基本指标?
But this doesn't show how you actually tie the ga function to your GA account/client ID.
您只需将 tracking ID(其格式类似于 UA-XXXXX-Y
)放在 UA-XXXXX-Y
位置。其他都不需要改变。
顺便说一句,GA 会在 Admin > Tracking Info
部分以及您首次创建 account/property.
部分时为您提供确切的代码,包括跟踪 ID
Then you have this behemoth of JS, but that looks totally different than the first snippet above.
这是为了获取数据 out 的 GA,例如自定义仪表板。如果您只想在 Google Analytics 界面中查看漂亮的统计数据,请忽略那部分文档。
我正在尝试让我的 JS 页面将基本指标报告回我的 GA 帐户。然而,Google 文档并没有真正清晰地/一致地阐明如何实现这一点。一方面,您有 analytics.js
片段:
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
但这并没有显示您实际上是如何将 ga
函数与您的 GA account/client ID 联系起来的。
那么您有 this behemoth of JS, but that looks totally different than the first snippet above. So I ask, can someone explain and provide an SSCCE 个所需的 JS 来实际从页面发回基本指标?
But this doesn't show how you actually tie the ga function to your GA account/client ID.
您只需将 tracking ID(其格式类似于 UA-XXXXX-Y
)放在 UA-XXXXX-Y
位置。其他都不需要改变。
顺便说一句,GA 会在 Admin > Tracking Info
部分以及您首次创建 account/property.
Then you have this behemoth of JS, but that looks totally different than the first snippet above.
这是为了获取数据 out 的 GA,例如自定义仪表板。如果您只想在 Google Analytics 界面中查看漂亮的统计数据,请忽略那部分文档。