Screen pixel ratios

Currently I can read the screen resolutions from the analytics. However, nowadays that alone doesn’t say that much. Different devices have also different pixel densities (1x, 2x, 3x). It would be interesting to see the device pixel ratio/dppx information too. It’s relevant when optimising images. However, I can’t find actual stats on that online.

For example if most visitor devices are 2x (which I assume), than it might not make sense to offer a 1x image at all.

https://www.mydevice.io/

Is this something that could be added, or is there a quick way to track it myself as with some custom event when a user visits a page?

Hi Kasper,

we currently use screen.width, which returns the screen resolution in CSS pixel:

I think this is reasonable, but we’ll think about adding support for dppx :slight_smile:

Yes, I’m’ aware of the width property. Just figuring out if it makes sense to serve smaller images.

I tracked it now as an event. In the end it’s just to get an idea, not a metric I need to keep tracking.

 <script defer type="text/javascript">
  document.addEventListener("DOMContentLoaded", () => {

      const dprFlag = localStorage.getItem("pirsch_dpr");

      if(!dprFlag) {
          pirsch("Screen DPR", {
                  duration: window.devicePixelRatio,
                  meta: {
                      dpr: window.devicePixelRatio
                  }
              }).then(() => {
                  localStorage.setItem("pirsch_dpr", true);
              }).catch(e => {
                  console.error(e); 
              }
          );
      }
      else {
          console.log("dpr already sent");
          return;
      }
  });
     
</script>

Only the duration parameter is a bit vague to me. Is that used to calculate some average?

1 Like

This is how it looks. Indeed duration seems to be averaged.

Yes, duration is a bit special as it is used to calculate an average. Usually for time-related things (read time), but you can use it for whatever you like :slight_smile:

Technically, we recently replaced it with custom metrics, that are a bit more flexible. However, I think your solution works well :+1:

Do you have documentation on the custom metrics? I didn’t came across it when reading the documentation on events, but maybe I overlooked it.

Sure! It requires a Plus subscription though. It’s part of the conversion goals article:

1 Like