Table of Contents
代码
Google Analytics自定义变量参数详解
扩展
Home php教程 php手册 Google Analytics谷歌统计来访评论者

Google Analytics谷歌统计来访评论者

Jun 06, 2016 pm 08:09 PM
google statistics Google

代码 以下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的人
}
?>
Copy after login

然后在ga统计代码里加上一行, (可以加在_gaq.push(['_trackPageview']);下面) :

_gaq.push(['_setCustomVar', 1, 'Reviewer', '<?php echo $fk;?>', 1]);
Copy after login

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

ga-reviewers (3)

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

Google Analytics自定义变量参数详解

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

_gaq.push(['_setCustomVar', 'index', 'name', 'value', 'opt_scope']);
Copy after login
  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"; }
Copy after login

GA代码部分

_gaq.push(['_setCustomVar', 2, 'IP', '<?php echo $ip;?>', 1]);
Copy after login

如图:

ga-reviewers (2)

收工, 匿了~
Statement of this Website
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Who actually owns Google? Who actually owns Google? Apr 02, 2025 pm 04:01 PM

Google is owned by Alphabet Inc., which is controlled by Larry Page and Sergey Bring: 1) The founder ensures control of the company by holding Class B shares (10 votes per share); 2) Alphabet's Class A and Class C shares are circulated in the open market and employee stock ownership plans, respectively, but do not affect the founder's control.

Tutorial on how to register, use and cancel Ouyi okex account Tutorial on how to register, use and cancel Ouyi okex account Mar 31, 2025 pm 04:21 PM

This article introduces in detail the registration, use and cancellation procedures of Ouyi OKEx account. To register, you need to download the APP, enter your mobile phone number or email address to register, and complete real-name authentication. The usage covers the operation steps such as login, recharge and withdrawal, transaction and security settings. To cancel an account, you need to contact Ouyi OKEx customer service, provide necessary information and wait for processing, and finally obtain the account cancellation confirmation. Through this article, users can easily master the complete life cycle management of Ouyi OKEx account and conduct digital asset transactions safely and conveniently.

What is Google lady's name? What is Google lady's name? Apr 06, 2025 am 12:01 AM

Googlelady's name is Google Assistant. 1. Google Assistant is an intelligent virtual assistant developed by Google, using NLP, ML and voice recognition technologies to interact with users. 2. Its working principle includes speech recognition, natural language processing, response generation and task execution. 3. Users can interact with basic and advanced through APIs, such as querying weather or controlling smart home devices.

How to optimize jieba word segmentation to improve the keyword extraction effect of scenic spot comments? How to optimize jieba word segmentation to improve the keyword extraction effect of scenic spot comments? Apr 01, 2025 pm 06:24 PM

How to optimize jieba word segmentation to improve keyword extraction of scenic spot comments? When using jieba word segmentation to process scenic spot comment data, if the word segmentation results are ignored...

Tutorial on using gate.io mobile app Tutorial on using gate.io mobile app Mar 26, 2025 pm 05:15 PM

Tutorial on using gate.io mobile app: 1. For Android users, visit the official Gate.io website and download the Android installation package, you may need to allow the installation of applications from unknown sources in your mobile phone settings; 2. For iOS users, search "Gate.io" in the App Store to download.

The latest updates to the oldest virtual currency rankings The latest updates to the oldest virtual currency rankings Apr 22, 2025 am 07:18 AM

The ranking of virtual currencies’ “oldest” is as follows: 1. Bitcoin (BTC), issued on January 3, 2009, is the first decentralized digital currency. 2. Litecoin (LTC), released on October 7, 2011, is known as the "lightweight version of Bitcoin". 3. Ripple (XRP), issued in 2011, is designed for cross-border payments. 4. Dogecoin (DOGE), issued on December 6, 2013, is a "meme coin" based on the Litecoin code. 5. Ethereum (ETH), released on July 30, 2015, is the first platform to support smart contracts. 6. Tether (USDT), issued in 2014, is the first stablecoin to be anchored to the US dollar 1:1. 7. ADA,

What is Google's old name? What is Google's old name? Apr 05, 2025 am 12:12 AM

Google'soldnamewas"Backrub,"reflectingitsinitialfocusonanalyzingbacklinks.1)StartedasBackrubatStanfordin1996,itusedabasicbacklinkalgorithm.2)RebrandedtoGooglein1997,symbolizingabroaderambitiontoorganizeinternetinformation.3)EvolvedwithPageR

Web IDE directory tree indentation: Why are the rendering results of Google Chrome and Firefox browsers different? Web IDE directory tree indentation: Why are the rendering results of Google Chrome and Firefox browsers different? Apr 04, 2025 pm 10:15 PM

About the rendering differences of WebIDE directory trees under different browsers This article will explore a rename of the Web in Google Chrome and Firefox...

See all articles