HiDPI display visits

How can I track HiDPI display visits (devicePixelRatio >= 1.5)?

Many thanks,


They should be tracked already? What’s the exact problem?

I am confused because, I can`t find any way to report the devicePixelRatio (and not the resultion in general) out-of-the-box.
What about custom variables to track devices that spot CSS pixel ratio >=1.5 ?

Ah ok, you could implement this using a custom variable for sure. Right now Piwik only captures the screen resolution and doesn’t calculate the pixel ratio.

Thanks so far, to create a custom variable should be no problem. But I think something is missing to create the PixelRatio-test. First I need someting like:
var (window.devicePixelRatio >= 1.5) “high” : “normal”;

Or maybe I’m simply wrong? :wink:

Does anybody have a working example?

At the moment the exact realisation is still inexplicit for me…

Hi Baenech i think instead of using a custom variable you could tackle it a different way…

You are interested in getting a total number based on pixel ratio. From a list of results you could have lets say 30 or 40 results in a given time frame. You could eventually make yourself a list of accepted ratios that qualify. So lets say by the time you look at your results you are left with 10 or 15 of them. You then could filter your results from the list of the total resolutions. Piwik results can be filtered. Doesnt require a custom variable, will capture those that you qualify as being high ratio. Its indirect but gives you the same result!


I do not really understand how that could work, because Piwik does not recognise the difference between screen resolution and CSS pixel ratio - it is completely different.

I finally found a solution … but only for Google Analytics. You have to set up a custom segment in Analytics to pick up that variable:

var pixelRatio = (window.devicePixelRatio >= 1.5) ? “high” : “normal”;
_gaq.push([’_setCustomVar’, 3, ‘PixelRatio’, pixelRatio, 2 ]);

But i won`t use Google Analytics! Has anyone an idea - how is it possible to implement such a thing in Piwik?

The solution for Piwik (asuming you use the async tracker) is very similar:

var devicePixelRatio=(window.devicePixelRatio>1)?window.devicePixelRatio:'normal or unknown'; 
_paq.push(['setCustomVariable',1,'devicePixelRatio', devicePixelRatio, 'page']);

This could, of course, need some testing and verification. You should probably test to see that ‘devicePixelRatio’ is available in the window object before using it.

var devicePixelRatio=('devicePixelRatio' in window)?window.devicePixelRatio:'unknown'; 

Thank you for that answer, Aeyoun. (tu)
I try your solution as soon as possible!