计算忽略搜索引擎的页面的观看次数? [英] Counting number of views for a page ignoring search engines?

查看:74
本文介绍了计算忽略搜索引擎的页面的观看次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到StackOverflow对每个问题都有一个视图计数,并且这些视图编号相当低且准确.

I notice that StackOverflow has a views count for each question and that these view numbers are fairly low and accurate.

我在一个网站上也有类似的事情.当页面在后端代码中加载时,它基本上记录命中".不幸的是,它也会对搜索引擎中的点击数产生giving肿且不准确的数字.

I have a similar thing on one of my sites. It basically logs a "hit" whenever the page is loaded in the backend code. Unfortunately it also does this for search engine hits giving bloated and inaccurate numbers.

我猜不算机器人的一种方法是在页面加载后通过AJAX调用进行视图计数,但是我敢肯定还有其他更好的方法可以忽略点击计数器中的搜索引擎,同时仍然让他们来抓取您的网站.你知道吗?

I guess one way to not count a robot would be to do the view counting with an AJAX call once the page has loaded, but I'm sure there's other, better ways to ignore search engines in your hit counters whilst still letting them in to crawl your site. Do you know any?

推荐答案

AJAX调用可以做到,但通常搜索引擎不会加载图片,javascript或CSS文件,因此在其中包含其中一个文件可能会更容易页面,并在文件请求中将您要针对其记录请求的页面的URL作为参数传递.

An AJAX call will do it, but usually search engines will not load images, javascript or CSS files, so it may be easier to include one of those files in the page, and pass the URL of the page you want to log a request against as a parameter in the file request.

例如,在页面中...

For example, in the page...

http://www.example.com/example.html

您可能会在标题部分

<link href="empty.css?log=example.html" rel="stylesheet" type="text/css" />

并让您的服务器端记录该请求,然后返回一个空的CSS文件.同样的方法也适用于JavaScript或图像文件,尽管在所有情况下,您都需要仔细查看可能发生的缓存.

And have your server side log the request, then return an empty css file. The same approach would apply to JavaScript or and image file, though in all cases you'll want to look carefully at what caching might take place.

另一种选择是根据搜索引擎的用户代理来消除搜索引擎. http://user-agents.org/上有很多可能的用户代理,可以帮助您入门.当然,您可以采用另一种方式,仅计算来自您所知道的Web浏览器的请求(覆盖IE,Firefox,Safari,Opera和Opera,而这种新颖的Chrome可以使您获得99%的访问权限).

Another option would be to eliminate the search engines based on their user agent. There's a big list of possible user agents at http://user-agents.org/ to get you started. Of course, you could go the other way, and only count requests from things you know are web browsers (covering IE, Firefox, Safari, Opera and this newfangled Chrome thing would get you 99% of the way there).

使用诸如 awstats 之类的日志分析工具或诸如

Even easier would be to use a log analytics tool like awstats or a service like Google analytics, both of which have already solved this problem.

这篇关于计算忽略搜索引擎的页面的观看次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆