代码 以下PHP代码加在Google Analysis统计代码之前 ?phpif ($_COOKIE["comment_author_" . COOKIEHASH]!="") {$fk = $_COOKIE['comment_author_'.COOKIEHASH];} elseif ($_COOKIE["wordpress_logged_in_" . COOKIEHASH]!="") {$fk = "admin";//自己} else {$
以下PHP代码加在Google Analysis统计代码之前
<?php if ($_COOKIE["comment_author_" . COOKIEHASH]!="") { $fk = $_COOKIE['comment_author_'.COOKIEHASH]; } elseif ($_COOKIE["wordpress_logged_in_" . COOKIEHASH]!="") { $fk = "admin";//自己 } else { $fk ="anonymous user";//没有评论cookies的人 } ?>
然后在ga统计代码里加上一行, (可以加在_gaq.push(['_trackPageview']);
下面) :
_gaq.push(['_setCustomVar', 1, 'Reviewer', '<?php echo $fk;?>', 1]);
然后等第二天就能看到统计了, 在受众群体 – 自定义 – 自定义变量中查看, 可以看到如下图所示:
Google Analysis自定义变量(CustomVariables)有4个自定义参数:
_gaq.push(['_setCustomVar', 'index', 'name', 'value', 'opt_scope']);
参考文档: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables?hl=zh-CN
以此类推还可以统计访客IP, 因为谷歌统计默认不会统计具体IP
PHP部分:
if(!empty($_SERVER['REMOTE_ADDR'])){ $ip = $_SERVER['REMOTE_ADDR']; } else { $ip = "null"; }
GA代码部分
_gaq.push(['_setCustomVar', 2, 'IP', '<?php echo $ip;?>', 1]);
如图:
ga-reviewers is coded by http://xiaohudie.net. Any posts here is one hundred percent original, so please keep my link so as not to hurt this pretty girl