How to format the userId in Google Analytics script?

戏子无情 提交于 2019-12-12 03:39:29

问题


for my static HTML webside I embedded this recommended script code to every page of the side.

<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}});

The question is: how to format my known Google analytics userId into this place {{USERID}}? Is it With brackets?, with quotes? Thanks for your help.


回答1:


The analytics.js fields reference lists UserID as format type "text", which means you pass it in like you would any other string value in Javascript (i.e. in as quoted string).

In fact the same page has examples:

// 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');


来源:https://stackoverflow.com/questions/43324058/how-to-format-the-userid-in-google-analytics-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!