How to track hits of a single media file?

I have multiple media files in my WordPress Media Library. Icons, Images, PDF’s and the like. I would like to have a stat counter, that gives me a statistic of the downloads/hits of those files, individually.

I already use WP SlimStat to track page view, and I am quite happy with it. However, I have not found a possibility to track those media files.

Read More

How can I do this?

Related posts

Leave a Reply

3 comments

  1. You could use Google Analytics for WordPress. Here’s an excerpt from their FAQ on how you could set it to track certain file types:

    How can I track downloads? Check the box for “Track outbound clicks &
    downloads”, after that, make sure the file types you want to track are
    listed in the box of extensions to track as downloads. You’ll find
    this input field under “Advanced”.

  2. Using Google Analytics will only collect clicks on your web pages, it will not count hits from external sites, RSS feeds, apps, etc. For this you’ll need to utilise your server log files.

    AWStats is good for this but it is overkill for a single file – you’d need to log in, set the timeframe to a large span, then browse for your file… it would be much easier if the WP files admin could check the server logs for definitive all-time hits for each file, but I am yet to find a plugin for this.

  3. If you need to track single file, and you have the URL of the file, and you have the access.log file set up right, then you can just use grep Linux command.

    grep "/downloads/my-file-name.media" /var/log/access.log

    To get the number of requests

    grep -c "/downloads/my-file-name.media" /var/log/access.log
    or

    grep "/downloads/my-file-name.media" /var/log/access.log | wc -l