从网站/cdn 跟踪下载完成情况

2021-12-29 00:00:00 download analytics php javascript drupal

我有一个 Drupal 网站,用户在该网站上点击一个链接,从内容交付网络 (CDN) 启动文件下载.脚本正在跟踪单击链接以开始下载过程的用户数量.我正在寻找有关如何跟踪成功完成下载过程的用户数量的建议.

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.

推荐答案

如果您只需要下载次数,只需从 CDN 中获取原始日志并通过日志分析工具运行它们.大多数 CDN 提供每日访问日志作为标准服务.较大的玩家可以做每小时记录或更好.

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.

最佳解决方案取决于您的 CDN,所以如果您还没有,请与他们联系.但是,这就是我过去的做法.

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.

对于生成的每个受保护的下载 URL,为发出请求的用户附加一个唯一的 ID.典型的 CDN 下载 URL 可能包含到期时间和哈希值以防止篡改.您需要先检查您的 CDN,以确保您选择的变量名称不会与其 API 冲突.在我们的例子中,我们同意使用前缀 ign_*(意思是忽略.)

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.)

之前:

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 的下载链接):

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.

在我们的例子中,我们每 15 分钟就有一次可用的日志,我自动执行了获取和处理以启用字节级别的每用户下载配额.

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.

要记住的一件事是,如果您要自己处理日志,请将 HTTP 206 部分条目组合在一起.特别是如果您对已完成下载的数量"感兴趣.

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."

相关文章