计算网站上几个文件下载次数的最佳方法 [英] Best way to count number of downloads of several files on website

查看:74
本文介绍了计算网站上几个文件下载次数的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是计算网站上几个文件下载次数的最佳方式

The question is "Best way to count number of downloads of several files on website"

我想做的事情:


  1. 跟踪和计算多个文件的下载次数

  2. 对于具有不同扩展名的文件。 (foo.zip,bar.tar.gz,foo2.zip)

  3. 避免依赖服务器端代码。

我已经看到了使用Apache access来计算文件下载的多个答案.log
cat /path/to/access.log | grep foo.zip | grep 200 | wc -l <​​/ code>
来自计算网站上文件下载的最佳方式
,这是一个雄辩的解决方案,但需要访问后端日志文件。我希望使用一个大多数javascript的解决方案,它也可以调用php部分的代码。

I've seen multiple answers for counting the file's downloads with the Apache access.log cat /path/to/access.log | grep foo.zip | grep 200 | wc -l from Best way to count file downloads on a website , which is an eloquent solution however requires access to the backend log file. I was hoping to use an mostly-javascript solution, Which could also make a call to a php portion of code.

推荐答案

为什么不使用Google Analytics?

Why not use Google Analytics?

https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide?hl=es

如果您的网站已启用Google Analytics,您只需向链接添加onclick事件,即可创建点击链接的计数。

If your website already has Google Analytics enabled, you can simply add an onclick event to the links, allowing it to create a count of when the links are clicked.

对于您的示例,链接如下所示:

For your example the links would look like:

<a onclick="var that=this;_gaq.push(['_trackEvent','Download','foo',this.href]);setTimeout(function(){location.href=that.href;},400);return false;" href="downloads/foo.zip">Download foo.zip</a>

<a onclick="var that=this;_gaq.push(['_trackEvent','Download','bar',this.href]);setTimeout(function(){location.href=that.href;},400);return false;" href="downloads/bar.tar.gz">Download foo.zip</a>

<a onclick="var that=this;_gaq.push(['_trackEvent','Download','foo2',this.href]);setTimeout(function(){location.href=that.href;},400);return false;" href="downloads/foo2.zip">Download foo.zip</a>

在Google Analytics中,下载事件将是所有三个文件的总下载次数,以及每个文件都有自己的事件foo,bar,foo2,这将是每个文件的单独下载次数。

In Google Analytics the "download" event would be the total number of downloads for all three files, and each file will have its own event "foo, bar, foo2" which will be each file's individual download count.

如果要从服务器端执行此操作,则需要在客户端中包含一些代码。使用工具已经存在比使用php和javascript酿造自己的解决方案更有效。

If you want to do this from the server side, you need to include some code in the client. It is more efficient use tools already exist than to brew your own solution using php and javascript.

这篇关于计算网站上几个文件下载次数的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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