I'd really like to be able to see how often a contributed file on Wikimedia Commons was viewed, specifically for images photgraphs and other images.
The webrequest data collected in production with varnishkafka does already include all file urls from upload.wikimedia.org (for all file types, and all wikis).
It is aggregated for all file types by file name (e.g. hits on thumbnails and transcoded versions count toward the original). See also https://wikitech.wikimedia.org/wiki/Analytics/Data_Lake/Traffic/Mediacounts and https://dumps.wikimedia.org/other/mediacounts/.
Index and query
As far as I know, these are not currently indexed or made queryable in production. But if they would, it would make a very neat addition to the Analytics Query Service (AQS; the metrics at https://wikimedia.org/api/rest_v1/)
There is currently some level of aggregation happening in Toolforge somewhere, which is what powers https://tools.wmflabs.org/mediaviews/, but this seems currently limited to playable files only (e.g. file names ending with audio/video file extensions). At T149642#3028288, it was hinted at supporting images, but this doesn't currently seem to be the case. I'm not sure whether this is a filter or a technical limitation.
The aggregation is exposed at https://tools.wmflabs.org/mediaviews-api/api/2, but I couldn't find the source of it. It seems similar to https://github.com/harej/mediaplaycounts but the code hosted there seems to actually have support for images, but it seems this tool isn't operational currently (would presumably at https://tools.wmflabs.org/mediaplaycounts/).
There are a lot of ideas of how such an API could be used, including:
- Integrate on Wikimedia Commons in production via on action=info, the same way we do for articles currently.
- Integrate with https://tools.wmflabs.org/mediaviews/ to see historical views of multiple files.
- A pageviews-tool interface to see stats for all images uploaded by a given user (similar to https://tools.wmflabs.org/userviews/, but for file uploads).
- a pageviews-tool interface to see stats by category (like https://tools.wmflabs.org/massviews/).
I think for the purposes of this task, any one of these would suffice to close, the rest can be done later.