search
Homephp教程php手册Google Analytics谷歌统计来访评论者

代码 以下PHP代码加在Google Analysis统计代码之前 ?phpif ($_COOKIE["comment_author_" . COOKIEHASH]!="") {$fk = $_COOKIE['comment_author_'.COOKIEHASH];} elseif ($_COOKIE["wordpress_logged_in_" . COOKIEHASH]!="") {$fk = "admin";//自己} else {$

ga-reviewers (1)

代码

以下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]);

然后等第二天就能看到统计了, 在受众群体 – 自定义 – 自定义变量中查看, 可以看到如下图所示:

ga-reviewers (3)

点进去就可以看到效果, 如开头的图所示

Google Analytics自定义变量参数详解

Google Analysis自定义变量(CustomVariables)有4个自定义参数:

_gaq.push(['_setCustomVar', 'index', 'name', 'value', 'opt_scope']);
  1. index — 必选, 自定义变量的键值, 可选范围 1 – 5,
  2. name — 必选, 填自定义变量的名称, 如”Reviewer” “评论者”
  3. value — 必选, 变量的值也就是统计到的数据
  4. 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 (2)

收工, 匿了~
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

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

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

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

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),