arp242 / goatcounter

Easy web analytics. No tracking of personal data.
https://www.goatcounter.com
Other
4.43k stars 177 forks source link

Feature Request: Page Load Time #519

Open blox814123 opened 2 years ago

blox814123 commented 2 years ago

In contrast to other self-hosted analytics like Shynet and plausible, goatcounter doesn't measure page load time. This seems to be a basic feature necessary for troubleshooting and measuring performance. Would be aprecciated if you added it.

rouilj commented 2 years ago

Could you use events for that? Maybe add

  <script>
      window.mod_pagespeed_start = Number(new Date());
  </script>

at the top of the head section. Then add:

<script>
function g(){
    let payload = 'load:'+ (Number(new Date())-window.mod_pagespeed_start);
    window.goatcounter.count({
        path: function(p) { return 'load-time-' + p },
        title: payload,
        event: true,
    });
};

let f = window.addEventListener;
if (f) {
    f('load',g,false);
} else {
    f=window.attachEvent;
    if (f) {
        f('onload',g);
    }
};
</script>

at the bottom of the page before the /body tag.

I am not precisely sure how to pull event data, you might need to use SQL to handle it.

Note that goatcounter's count.js script can't do it. Usually, it's loaded async so won't be able to run first thing during the page load to record start time or be able to run at the end of the page. The earliest it will run will be after it loads sometime after the page is displayed.

You may need to defer the window.goatcounter call as described at https://www.goatcounter.com/help/js#methods-44.