pythonbashmonitoringevent-tracking

Find out the frequency that someone is using my code (bash or python)


Working in academia, one of the most important things for us when applying for research funding is to be able to evidence how other people benefit from your work.

Using number of downloads is a poor metric for this. It would be much better if we could show how frequently the code is used (i.e. 10 people using something daily is better than 100 downloading but never using).

Is there a way to do this using bash or python scripts? My idea so far has been around using wget or curl pointed at a url (used only for this) which has google analytics attached to it. This way we could monitor number of executions and location (this info would be sufficient).

I'm not quite sure how it would be implemented. Any suggestions?

NOTE: the code will be open source, so they could see what we're doing, we would include an explanation why it's useful for grants (and therefore their benefit), have a switch for them to disable this feature if needs be and the script would still run if there was no internet connection.


Solution

  • A few considerations:

    1. Just fetching a page with Google Analytics on it won't work because the actual analytics occurs as a result of some JavaScript which is loaded. You'll either need to run some very simple code on a server or use some service with a HTTP API. Sticking with using Google Analytics, there's the pretty simple to use Google Analytics Measurement Protocol.

    2. You'll need to make sure that the request isn't blocking, by using async or spawning another thread or through some other method.

    3. In terms of actual implementation if you're using Python you can use the standard library urllib.request.urlopen to make the request without needing to worry about any dependencies, or alternatively choose to use the popular requests library.