如何跟踪从远程网站下载的文件 [英] How can I track downloads of files from remote websites

查看:37
本文介绍了如何跟踪从远程网站下载的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在共享存储在我的服务器中的文件(例如 pdf)的链接.是否可以在某些用户下载文件时进行跟踪?我无权访问其他页面的脚本,但我认为我可以跟踪传入服务器的请求.这在计算上会很昂贵吗?有什么提示可以看哪个方向?

I am sharing the link of a file (e.g. pdf), which is stored in my server. Is it possible to track whenever some user is downloading the file? I don't have access to the script of the other page but I thought I could track the incoming requests to my server. Would that be computationally expensive? Any hints towards which direction to look?

推荐答案

您可以使用 测量协议,一种向 Google Analytics 跟踪服务器发送的 http 跟踪请求的语言不可知描述.

You can use the measurement protocol, a language agnostic description of a http tracking request to the Google Analytics tracking server.

您的问题是您在点击和下载之间没有脚本来发送跟踪请求.一种可能的解决方法是使用服务器访问日志,前提是您对服务器有一定的控制权.

The problem in your case is that you do not have a script between the click and the download to send the tracking request. One possible workaround would be to use the server access log, provided you have some control over the server.

例如,Apache Web 服务器可以使用 管道日志,例如相反,如果直接写入文件,日志条目将传递给脚本或程序.我有理由相信其他服务器也有类似的东西.

For example the Apache web server can user piped logs, e.g. instead if being written directly to a file the log entry is passed to a script or program. I'm reasonably sure that other servers have something similar.

您可以将日志传送到脚本,该脚本评估日志条目是否指向您的 pdf 文件的 URL,如果是,则将信息分解为单独的数据字段,并通过您选择的编程语言将它们发送给 GA跟踪服务器.

You could pipe the logs to a script that evaluates if the log entry points at the URL of your pdf file, and if so breaks down the info into individual data fields and sends them via a programming language of your choice to the GA tracking server.

如果您无法将服务器控制到那个级别,您需要在服务器上放置一个与原始文件具有相同名称和位置的脚本,将 pdf 扩展名映射到您选择的脚本解释器(在 apache 中通过 <一个 href="http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype" rel="nofollow noreferrer">addType,可以通过 htaccess 文件完成许多主机) 并让脚本在发送原始文件之前发送跟踪请求.

If you cannot control the server to that level you'd need to place a script with the same name and location as the original file on the server, map the pdf extension to a script interpreter of your choice (in apache via addType, which with many hosts can be done via a htaccess file) and have the script sending the tracking request before delivering the original file.

这两种解决方案都需要少量的编程实践(后者比前者少得多).管道日志可能很昂贵,具体取决于对服务器的请求数量(不过,您可以为可下载文件创建额外的日志文件).中间脚本不会是一项昂贵的操作.

Both solutions require a modicum of programming practice (the latter much less than the former). Piping logs might be expensive, depending on the number of requests to your server (you might create an extra log file for downloadable files, though). An intermediary script would not be an expensive operation.

这篇关于如何跟踪从远程网站下载的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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