minetest.github.io icon indicating copy to clipboard operation
minetest.github.io copied to clipboard

Download counter for website

Open Poikilos opened this issue 7 years ago • 6 comments
trafficstars

Hey, how about a download counter for the website? Minetest needs some street cred. You could probably figure out where to start the counter using GitHub's stats, or maybe even pull in the number from there if that feature is in GitHub's API (it does not appear to be in the documentation)--I don't know much about that though. It might be hard to do in an ongoing way since there are so many releases. I have created a support request with GitHub on this in case noone knows a good way to do this.

Option 2: If there is no way to get a real number, then you could honestly just have a visit count on the download page, which is probably available via the web server API in a much simpler way. If it is not, maybe the administrator could see the visit count for the download page, start the count at that number, then update the visit count of the download page whenever the page is generated (or since most of the page seems to use html files, at least via an XMLHttpRequest). Since you have html files in this repo, I am assuming the web host is fairly normal (not some kind of CMS deal), and that php could be used.

If GitHub support answers the request I sent favorably, or if not but a website admin can give me a current count via the web host's website control panel (for implementing option 2), I could code this.

Poikilos avatar May 20 '18 01:05 Poikilos

The website is hosted on github pages and static only. Ie: no PHP or server stuff allowed

rubenwardy avatar May 20 '18 07:05 rubenwardy

pull in the number from there if that feature is in GitHub's API (it does not appear to be in the documentation)

github's api already supports this: https://api.github.com/repos/minetest/minetest/releases/tags/0.4.16

sfan5 avatar May 20 '18 09:05 sfan5

Well, it works. It gets throttled (rate control message appears in browser console) after a couple dozen refreshes or so, but that only affects the internet connection accessing the stats (though the error alert is shown on my WiFi connection, it does not appear on my mobile connection) temporarily, for about an hour or more. Here is the example (may have older version of code due to caching by my web host): expertmultimedia.com/enliven/13/index.html

Here is the code that works (uses bootstrap):

      <div style="text-align:center">
        <div name="statsArea" id="statsArea" style="text-align:center">
        </div>
      </div>
      <script>
        var releasesUrl = "https://api.github.com/repos/minetest/minetest/releases";
        var targetElement = document.getElementById("statsArea");
        //targetElement.innerHTML = 'loading stats...<br/>images/CC_BY-SA_plain300.png<img src="images/dog_typing-CC_BY-SA_LillieLeDorre.gif"><br/><small><small><span style="color:lightgray"><a href="https://imgur.com/tbIq2nD">CC-BY 3.0 Lillie Le Dorre</a></span></small></small>';
        targetElement.innerHTML = 'loading stats...';
        var request = new XMLHttpRequest();
        request.open('GET', releasesUrl, true);

        request.onload = function() {
          if (request.status >= 200 && request.status < 400) {
            var releases = JSON.parse(request.responseText);
            releasesCount = releases.length;
            dlCount = 0;
            var r=0;
            for (r=0; r<releasesCount; r++) {
              var assets = releases[r].assets;
              var assetCount = assets.length;
              for (var a=0; a<assetCount; a++) {
                dlCount += assets[a].download_count;
                targetElement.innerHTML = 'Minetest has been downloaded<br/><span class="border border-secondary rounded">&nbsp;'+dlCount.toLocaleString()+'...&nbsp;</span><br/>times';
              }
            }
            targetElement.innerHTML = 'Minetest has been downloaded<br/><span class="border border-success rounded">&nbsp;'+dlCount.toLocaleString()+'&nbsp;</span><br/>times';
          } else {
            targetElement.innerHTML = '<div class="alert alert-error">stats are unavailable</div>';
          }
        };

        request.onerror = function() {
          targetElement.innerHTML = '<div class="alert alert-error">error accessing stats</div>';
        };

        request.send();


      </script>

For the record, including only releases downloaded via the website, Minetest has been downloaded 1,029,453 times!

Poikilos avatar May 20 '18 20:05 Poikilos

@poikilos If your code works, why not open a PR?

binyamin avatar Apr 22 '19 01:04 binyamin

Is this still desired today? I'm not sure if displaying download counts on the website solves a real use case.

Calinou avatar Jun 02 '20 13:06 Calinou

Keep in mind that https://api.github.com/repos/minetest/minetest/releases is only half the story: On top of that there are the downloads from the Google Play store (which probably provides another API), miscellaneous self-builds (should we count git cloning?) and various Linux repos (the PPA, AUR, Flatpak, Snap).

appgurueu avatar Jun 28 '22 10:06 appgurueu