google-analytics - 如何在Google Analytics(分析)脚本中设置userId的格式?

标签 google-analytics formatting code-snippets embedding

对于我的静态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/

相关文章:

linux - 将 bash/shell 脚本时间格式化为天、小时、分钟和秒

c# - 如何使用亚洲格式格式化钱

vim - vim 中的全局片段

javascript - 在 Wordpress 网站上使用 Google Analytics 的用户 ID 功能

ruby-on-rails - gabba gem 没有正确跟踪

python - 根据条件组合 Pandas 行

java - 按下按钮时使用 ZEST 框架绘制图形不起作用?

google-analytics - 如果有人访问网页,是否可以触发功能?

wordpress - 如何在magento/wordpress上分离Google Analytics

objective-c - 如何防止 xcode 将 <# #> 视为代码片段占位符