对于我的静态HTML网站,我将此推荐的脚本代码嵌入到该页面的每一页。
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96597161-1', 'auto');
ga('send', 'pageview');
ga('set', 'userId', {{USERID}});
问题是:
如何将我已知的Google Analytics(分析)userId格式化到此地方
{{USERID}}
?用括号括起来吗?
谢谢你的帮助。
最佳答案
analytics.js fields reference将UserID列出为格式为“文本”的类型,这意味着您可以像在Javascript中使用其他字符串值一样(例如,用引号引起来的字符串)来传递它。
实际上,同一页面上有一些示例:
// Set the user ID when creating the tracker.
ga('create', 'UA-XXXX-Y', {'userId': 'as8eknlll'});
// Alternatively, you may set the user ID via the `set` method.
ga('set', 'userId', 'as8eknlll');
关于google-analytics - 如何在Google Analytics(分析)脚本中设置userId的格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43324058/