Google analytics 如何在Google Analytics脚本中格式化用户ID?

Google analytics 如何在Google Analytics脚本中格式化用户ID?,google-analytics,formatting,code-snippets,embedding,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=

对于我的静态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}});

(函数(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]| |函数(){
(i[r].q=i[r].q | |[]).push(参数)},i[r].l=1*新日期();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(窗口、文档、“脚本”和https://www.google-analytics.com/analytics.js","ga",;
ga(“创建”、“UA-96597161-1”、“自动”);
ga(‘发送’、‘页面浏览’);
ga('set','userId',{{userId}});

问题是: 如何将我已知的Google analytics用户ID格式化到此位置
{{{userId}
? 它是用括号括起来的吗?是用引号括起来的吗? 感谢您的帮助。

将UserID列为格式类型“text”,这意味着您可以像在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');

为什么不试试呢?谢谢你@Elke Pierstoff。不能让它运行。我必须把脚本代码插入每一页,对吗?不仅仅是主页,对吧?是的。看看你的代码示例,你必须确保在页面浏览跟踪调用之前设置了用户id,否则就没有效果了。非常好@Elke Pierstoff。这条线现在作为三个ga(..)中的第一个移动。我是否必须为每一页的侧面设置一个BerichtsDatensicht?或者只是一个berichtsdatenasicht为边?实际上它需要在“create”之后,在“send”之前(对不起,应该更清楚)。创建一个额外视图并启用UserId功能;这将适用于发送用户ID的完整站点,并且不会跟踪不发送用户ID的会话。嗨,@Elke Piersdoff。我按照你的描述移动了这条线。现在它适用于主页。我必须在网站的10个页面中添加相同的代码行,对吗?而且在分析中,不需要为页面生成额外的Datenansichten,对吗?