然后将ga('set', 'userId', {{USER_ID}});
添加到我的跟踪代码...
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('send', 'pageview');
现在我的代码看起来像(include ('google-analytics.php')
)这个:
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', '<?=$seo['analytics'];?>', 'auto');
ga('send', 'pageview');
如何通过网站访问者(不是点击次数)获取php(或javascript)生成唯一ID,?
换句话说,如果相同的访问者点击了网站中的多个网页,我希望ID 保持相同的ID ,并且不会因每次点击(或刷新)而变化。
我尝试$seo['userID'] = uniqid();
,但每次点击或刷新都会改变。
我不知道将ga('set', 'userId', {{<?=$seo['userID'];?>}});
放在哪里......
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', '<?=$seo['analytics'];?>', 'auto');
ga('send', 'pageview');
...跟踪代码。
如果此ga('set', 'userId', {{<?=$seo['userID'];?>}});
是对其进行编码的正确方式,或此ga('set', 'userId', <?=$seo['userID'];?>});
,或此ga('set', 'userId', <?=$seo['userID'];?>);
等等......