我一直在为我公司的支持中心工作,我们需要在登录时跟踪个人用户.如果可能的话,我们也希望跟踪详细信息,例如访问的页面和在网站上花费的时间.我可以使用自定义变量跟踪有多少人登录该网站,但我无法跟踪单个用户.这是我用来尝试获取单个用户ID的代码:
$(document).ready( function() {
var welcomeEmail = document.getElementById('welcome_email').innerHTML;
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30086012-1']);
var welcomeEmail;
if( $('#welcome_email').length > 0 ) {
//This block of logic makes sure that the welcome_email element actually exists, it will not exist if a user is not logged in yet
welcomeEmail = document.getElementById('welcome_email').innerHTML;
}
_gaq.push(['_setCustomVar',1,'UserEmail',welcomeEmail,1]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; …
Run Code Online (Sandbox Code Playgroud)