代码 以下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 Analytics自定义变量参数详解
Google Analysis自定义变量(CustomVariables)有4个自定义参数:
_gaq.push(['_setCustomVar', 'index', 'name', 'value', 'opt_scope']);
- index — 必选, 自定义变量的键值, 可选范围 1 – 5,
- name — 必选, 填自定义变量的名称, 如”Reviewer” “评论者”
- value — 必选, 变量的值也就是统计到的数据
- opt_scope — 可选, 代表变量统计的类型/级别, 有3个参数: 1 (visitor-level 访客级别), 2 (session-level 访问级别), or 3 (page-level 页面级别).
参考文档: 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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),