我一直在为我的公司开发一个支持中心,我们需要在个人用户登录时对其进行跟踪。如果可能,我们还希望跟踪详细信息,例如访问的页面和在网站上花费的时间。我可以使用自定义变量跟踪有多少人登录到该站点,但我无法跟踪单个用户。这是我用来尝试获取个人用户 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]; s.parentNode.insertBefore(ga, s);
})();
我错过了什么/做错了什么。感谢任何反馈。