问题描述
我有一个Drupal网站,用户点击链接,启动从内容传送网络(CDN)下载文件。脚本正在跟踪点击链接的用户数以开始下载过程。我正在寻找关于如何跟踪成功完成下载过程的用户数量的建议。如果只有需要完成下载的号码,只需从CDN中获取原始日志,并通过日志分析工具运行它们。大多数CDN提供每日访问日志作为标准服务。更大的玩家可以做小时的日志或更好的。
最好的解决方案将取决于你的CDN,所以如果你还没有,请和他们交谈。但是,以下是我过去的做法。
对于生成的每个受保护的下载URL,为发出请求的用户附加唯一的ID。典型的CDN下载URL可能包含到期时间和散列,以防止篡改。您将首先检查您的CDN,以确保您选择不与其API冲突的变量名称。在我们的情况下,我们同意一个前缀为ign_ *(意思是忽略)。
之前:
http://cdn.example.com/path/to/file.ext?e=EXPIRES&h=HASH
之后:
http://cdn.example.com/path/to /file.ext?e=EXPIRES&ign_u=USERID&h=HASH
示例(下载链接用户1234):
http://cdn.example.com/path/to/file.ext?e=1356088260& ign_u = 1234& h = 39341385b9d99730646d927f620111e1
现在,当您下载原始日志时,每个条目可以关联您的一个用户只需解析查询字符串即可。从这里你可以从计算完成的下载次数到实现每个用户的下载报告来做一切。
在我们的例子中,我们每隔15分钟提供一次日志记录,自动获取和处理以启用字节级的每用户下载配额。
有一件事要记住,如果你要自己处理日志,将HTTP 206部分条目组合在一起。特别是如果您对完成的下载次数感兴趣。
I have a Drupal website where users are clicking on a link that initiates a file download from a content delivery network (CDN). A script is tracking the number of users who click the link to begin the download process. I'm looking for suggestions on how I might track the number of users who successfully complete the download process.
If you only need the number of completed downloads, just grab the raw logs from your CDN and run them through a log analysis tool. Most CDNs provide daily access logs as a standard service. The bigger players can do hourly logs or better.
The best solution will depend on your CDN, so talk to them if you haven't already. However, here's how I've done it in the past.
To each protected download URL generated, append a unique id for the user who made the request. A typical CDN download URL might contain an expiry time and a hash to prevent tampering. You'll want to check with your CDN first to make sure you pick a variable name that doesn't clash with their API. In our case we agreed on a prefix of ign_* (meaning ignore.)
Before:
http://cdn.example.com/path/to/file.ext?e=EXPIRES&h=HASH
After:
http://cdn.example.com/path/to/file.ext?e=EXPIRES&ign_u=USERID&h=HASH
Example (download link for user 1234):
http://cdn.example.com/path/to/file.ext?e=1356088260&ign_u=1234&h=39341385b9d99730646d927f620111e1
Now when you download your raw logs, each entry can be associated with one of your users simply by parsing the query string. From here you can do everything from counting the number of completed downloads, to implementing per-user download reports.
In our case, we had logs available every 15 minutes and I automated the fetching and processing to enable byte-level per-user download quotas.
One thing to keep in mind, if you're going to be processing the logs yourself, is to group HTTP 206 partial entries together. Particularly if you're interested in the "number of completed downloads."
这篇关于从网站/ cdn跟踪下载完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!