jsr
jsr copied to clipboard
Store download metrics + show most downloaded on home page
We already collect this information in GCP logs - we now need to aggregate & store it somewhere so we can display it.
Requests for surfacing download metrics on package pages have been closed as duplicates of this:
- #343
- #383
- edited to add #731
But this issue's title explicitly limits metrics' surfacing to showing on "the homepage", which given the "most downloaded" limit I take to mean the https://jsr.io/ homepage. Can we get an official comment on whether this issue includes support for surfacing download metrics on package pages?
edit: download metrics were added to package pages in April 2025
I believe this issue is important, specially in the package page (pointed out as not included by @olets).
The number of weekly downloads on npm is a significant indicator of a package's credibility, particularly for developers who are in a hurry. It frequently becomes a decisive factor in determining whether they will choose the package.
I am sure JSR will want that in order to overtake npm, if not now, in the future.
Now we already have Version Badge, JSR Score Badge and Scope Badge, it would be awesome to add Downloads (total/monthly/weekly) Badge! ❤️
I would like to help with this feature. I've read the README but nothing about logs is mentioned and I wonder how could I read/parse them (real time and old ones) to count downloads and have a valid data source for this. Anyone can help?
Note: I guess productizing this would require to store those counters into the database, or other persistent storage, instead of logs. But at least reading old logs would be useful for initializing that storage.
We already store download metrics and are available via an API endpoint, so the only thing needed to be added is the frontend
@crowlKats oh that sounds great! I'll play with it. Thanks
We already store download metrics and are available via an API endpoint
What endpoint is that?
We already store download metrics and are available via an API endpoint
What endpoint is that?
I don't think there is any available documentation yet. So, I crawled the source code and found the following:
-
Global metrics: https://jsr.io/api/metrics
-
Package specific download metrics:
https://jsr.io/api/scopes/{scope}/packages/{package}/downloadsFor example, to get the download metrics for the @std/assert package: https://jsr.io/api/scopes/std/packages/assert/downloads
Would anyone know how to turn this package-specific downloads endpoint into a shields.io dynamic badge? I'm having a hard time understanding where's the total downloads and how to make that JSON path query work.
@NatoBoram the endpoint in https://github.com/jsr-io/jsr/issues/14#issuecomment-2708489000 doesn't have precomputed "total downloads" or "weekly downloads" data points, and vanilla JSONPath doesn't have the functions needed to compute it in a shields query.
While waiting for #1182, you can fetch the data and reduce it to the value you're interested in. Then, you might be able to use that value directly in a static badge; or you could create your own API endpoint for that data (many popular frameworks support this) and use an endpoint badge.