Hi @godai
Yes, it’s possible to monitor file downloads for files already in your WordPress Media Library
Use PHP to Log Downloads:
- Hook into WordPress’s file access functions to log downloads in your database or a custom log file.
Example PHP Code Add Function.php :
function track_pdf_downloads() {
// Check if the request is for a Media Library file.
if (is_admin() || !isset($_SERVER['REQUEST_URI'])) {
return;
}
// Get the requested file URL.
$requested_file = $_SERVER['REQUEST_URI'];
// Check if it's a PDF file.
if (strpos($requested_file, '.pdf') !== false) {
// Log file location.
$log_file = WP_CONTENT_DIR . '/pdf-download-log.txt';
// Prepare log data.
$log_data = sprintf(
"[%s] File Downloaded: %s | IP: %s\n",
date('Y-m-d H:i:s'),
$requested_file,
$_SERVER['REMOTE_ADDR']
);
// Write to log file.
file_put_contents($log_file, $log_data, FILE_APPEND);
}
}
add_action('init', 'track_pdf_downloads');
Thread Starter
godai
(@godai)
Thank you.
Unfortunately, that is well over my knowledge to introduce by myself (positively zero PHP knowledge). I hoped for a ready solution, like a plugin of template code. But thanks anyway.
Please install this plugin.
Option 1: Using Plugins for Download Monitoring
Several plugins allow tracking downloads from your WordPress Media Library directly:1. Download Monitor
- Install and activate the Download Monitor plugin.
- While this plugin typically involves registering files, you can use extensions or customizations to monitor all Media Library downloads.
- Use the add-on “Advanced Media Reporting” to track Media Library files like PDFs without needing to re-upload them.
Thread Starter
godai
(@godai)
Thank you, I’ll look into it 🙂
Thread Starter
godai
(@godai)
Welp, looks like my installation does not have this kind of add-on available, neither free nor premium.