• Hello, I wonder if there is a way to monitor file downloads for files already existing in WordPress Library.

    I mean files already uploaded, basically all PDFs, and I would like to monitor them WITHOUT the need to add every single file to some download plugin by hand and paste special link in place – and that’s what all plugins I tried want me to do.

    So, is there a plugin that will let me check “PDFs” and tell me “oh, this one was opened 27 times”?

    Thanks.

    • This topic was modified 3 days, 8 hours ago by godai.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Subrata Debnath

    (@subrata-deb-nath)

    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.

    Subrata Debnath

    (@subrata-deb-nath)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.