Search code examples
javascriptjspanalytics

Can I call a routine or a function automatically when a File is accessed?


Pardon me if I am asking something really stupid. But this is what I want to implement as per my new role as a analytic Implementer. Some of our files (Mostly pdfs) are stored on a webserver (CDN server) to reduce some load of the application server.

We provide links to these file to all our users across the world. What I want is to track these file download whenever they occur. So I just wanted to know is there any way by which I can call a function or a routine from where I can make those tracking calls ?


Solution

  • Not really.

    If you are using a 3rd party web hosting as CDN, then you could simply get the Analytics reports using whatever tool your host offers.

    If you are running your own hosting box, you could install almost any analytics software on it to monitor access. Just one example is provided here: http://ruslany.net/2011/05/using-piwik-real-time-web-analytics-on-iis/

    The clean simple way, however, would be to have a simple web application running on that CDN server that accepts file requests and then returns the file. The advantages are that you could:

    • record whatever statistics you wish off it.
    • use widely available tools like Google Analytics
    • make dynamic decisions, one example of which is deciding version of file sent based on factors like user bandwidth, etc.
    • transparently handle missing files and path changes, so links will be valid forever
    • send different caching headers for different files
    • implement very simple access control and policy based restrictions