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.
How can I do this?
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:
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.
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