proxy代理   soft软件   IT 业界特快   norton 诺顿病毒库   代理列表   search FTP搜索   whois IP地理位置   blog 追求完美  
money理财   life生活   RSS聚合门户   firefox WEB浏览器   免费域名   typeset 假古文   AntiVirus 反病毒   ipcn 站点导航  

« Dell 宣布召回有问题隐患的电池 | Main | 网络投票机的 Curl 实现 »

August 16, 2006

JavaScript 在网站访问(PV)跟踪分析中的作用与主要实现

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。
https://windtear.net/archives/2006/08/16/001056.html
http://windtear.net/archives/2006/08/16/001056.html

JavaScript 在网站访问(PV)跟踪分析中的作用与主要实现

一般大网站的PV(PageView)分析都是通过在页面底部嵌套代码的方式收集收据
AC Nielsen 和 Google Analytics 也是如此

js 在这里起到的作用是收集信息 然后构造新的CGI URL
收集的信息包括:
Referer(document.referrer)  User-Agent(navigator.userAgent)  Cookie(document.cookie) 等
关于 Cookie 相关的处理可能稍多些

要通过 js 获取某一特定 cookie 值的话
需要先通过 indexOf  定位 cookie name 在 document.cookie 的位置
然后通过 .substring 获取 cookie value

设置cookie直接调用
document.cookie=
name+"="+value+"; expires=Wed, 23 Aug 2096 10:05:58 GMT; path=/; domain="+domain;
这个过程需要做的事是根据 document.URL 判断出 domain 并做好必要的分拆
为了保持唯一性 一般还会用一些随机数 Math.random().toString()

对一些关键字符还需要做 escape 处理
for(i=0;i<str.length;i++)
{if(str.charCodeAt(i)>=0&&str.charCodeAt(i)<=255){en=en+escape(str.charAt(i));}
如果分拆需要考虑 unicode 的 escape 详见
《编码与解码 javascript escaped UNICODE string 的解码 (php&perl)》

其中个别关键的设置信息可能需要容错 if(typeof(uid)=="undefined") ...

最后
document.open()
document.write("html code hear")
document.close

注意 AddType application/x-javascript .js
部署上需要在相关页面 </body>之前加上
<script type="text/javascript" src="http://domain.name/filename.js">
为了防止 script 被禁用
一般还会放一个
<noscript><img src="" height="1" width="1" style="display:none" alt=""></noscript>
图片的url设置上做一些技巧 然后收集log

大体如此
有兴趣的话大家可以参考门户网站或Google Analytics等的实现
本blog WWW

Posted by windtear at August 16, 2006 12:00 AM

本站使用中的任何问题,请与 windtear @ windtear.net 联系
Copyright© 1999-2024 Windtear. All rights reserved.