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.
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- Laravel Option Select - Default Issue
- How to toggle on Order in ReactJS
- PHP Recursively File Folder Scan Sorted by Modific
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:
After:
Example (download link for user 1234):
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."