Home > php教程 > php手册 > body text

博客评论回访者跟踪

WBOY
Release: 2016-06-06 20:07:19
Original
1534 people have browsed it

之前写了一大堆关于Google Analytics的文章,现在又想折腾回访者的跟踪 主要想了解评论者收到评论回复邮件后,回访博客的情况和行为 Analytics有跨域跟踪的功能,还可以传递cookies,但是在邮件里加入js,邮件提供商是否允许在邮件里运行js还是个问题, 折腾

之前写了一大堆关于Google Analytics的文章,现在又想折腾回访者的跟踪

主要想了解评论者收到评论回复邮件后,回访博客的情况和行为

Analytics有跨域跟踪的功能,还可以传递cookies,但是在邮件里加入js,邮件提供商是否允许在邮件里运行js还是个问题,

折腾了半天想到一个简单的办法,不过只能确定是否通过提醒邮件回访了博客

方法很简单,就是改造评论回复提醒邮件的链接,现在的短链接服务都提供统计功能,我把邮件内的链接替换为bit.ly的短链

这个链接除了收信人能点击到,还有我自己到bit.ly的后台能点击,其他人是不知道这个链接的

而每封评论回复提醒邮件的地址由于评论不同,生成的短链不同,因此只要通过后台查看这些链接是否被点击过就能了解到评论者是否回访了

这个方法也没完全解决需求,如果评论回访者没通过邮件连接,而是直接输入地址或者其他外链进来的,就没法跟踪到了

那样的话,可以通过判断cookies里是否有author_comments字段,不过本文不介绍那个方法

P.S.文章写的时间有点早了,现在已经使用了多说评论系统,暂时没法跟踪评论者点击提醒链接,如果你还是使用本地发送提醒链接,可以接着往下看

我之前使用的是Comment Reply Notification插件来实现评论提醒,找到228行的

$permalink =  get_comment_link($parent_id);
$mail_message = str_replace('[commentlink]', $permalink . "#comment-{$parent_id}", $mail_message);
Copy after login

修改为如下代码

$permalink =  get_comment_link($parent_id);
$linksource = '?utm_source=s.xfeng.me&utm_medium=mail&utm_campaign=myblog_link#';
$tmplink = str_replace('#',$linksource,$permalink);
$encodelink = urlencode($tmplink);
$biturl ="http://api.bit.ly/v3/shorten?login=your_username&apiKey=your_apikey&longUrl=$encodelink&format=json";
function bitly_curl( $url )
{
		if ( ! isset( $url ) )
				return false;
		if ( function_exists( 'curl_init' ) )
		{
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($ch, CURLOPT_URL, $url );
				$result = curl_exec($ch);
				curl_close($ch);
		}else{
				$result = file_get_contents( $url );
		}
		if ( ! empty( $result ) ) return json_decode( $result, true );
		return false;
}
$shortlink_response = bitly_curl($biturl);
if ( is_array( $shortlink_response )  && $shortlink_response['status_code'] == 200 )
{
		$shortlink = $shortlink_response['data']['url'];
}else{
		$shortlink = $tmplink;
}
$mail_message = str_replace('[commentlink]', $shortlink, $mail_message);
Copy after login

我这里给链接加了utm_source、utm_medium、utm_campaign,可以在Analytics里查看到这些链接被打开的数据,你也需要修改自己的utm_source

另外需要修改代码里biturl的your_username和your_apikey,替换为你自己的bit.ly用户名和apikey

邮件效果如下

这样你就能知道访客是否通过邮件回访了,虽然不完全满足需求,不过也算实现了一点功能吧

用Wordpress就得瞎折腾


作者:小峰JoysBoy@小峰网络遨游记 | About Me
地址:https://xfeng.me/comment-return-visitor-track/ | 4 条评论,看看别人说了些什么 | 03/19/2012
Category: PHP, wordpress
Post Tags: plugin, track, wordpress
本博客原创文字只代表本人某一时间内的观点或结论,与本人所在公司没有任何关系。
第三方若用于商业用途的转载,须取得本人授权。
Twitter | Google+ | FaceBook | DouBan | Yupoo | Flickr | Wakoopa
Copyright ? 2006 - 2012 XFeng.Me All Rights Reserved.
(详情请访问本站:小峰网络遨游记)


Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!