matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.87k stars 2.65k forks source link

piwik.JS: devicePixelRatio detection covers only Apple devices #4663

Open nkuehn opened 10 years ago

nkuehn commented 10 years ago

The devicePixelRatio detection in https://github.com/piwik/piwik/blob/master/js/piwik.js#L2242 makes a simple assumption that only Apple Retina devices have a physical screen resolution that differs from the logical (CSS pixel) resolution.

That leads to the issue that e.g. most Android hi-res devices aren't correctly detected and neither Win8 ones.

You can find a list of real CSS Pixel ratios here: http://en.wikipedia.org/wiki/List_of_displays_by_pixel_density Unfortunately not all Devices are configured on 1 1.5 2 2.5 3 etc... but some use in-between ratios.

My suggestion would be to use this (established) polyfill instead of the UA regexp: https://github.com/tysonmatanich/GetDevicePixelRatio/blob/master/getDevicePixelRatio.js

but I would add a rounding to 0.5 precision to not spam the Data with random outliers.

did I miss something? I'm not sure how such a change affects backwards compatibility of the data. If backwards compatibility is an issue (have to think about retina displays on desktops, too!), An alternative would be to define "res" as CSS resolution and report devicePixelRatio separately (See my P.P.S. below).

Greets, interested to hear what you think. Nikolaus

P.S.: Concerning the devicesDetection Plugin: I think it would be a never-ending uphill battle to try to maintain an always-up-to-date mapping of UA strings to devicePixelRatios on the server, which would be inherently unreliable all the time as Vendors are starting to anonymize the UA strings of the devices more and more.

P.P.S.:

mattab commented 10 years ago

If there is a bug in the devicePixelRatio we'd like to fix it for sure!

Could you give some examples of how changing the code, would change the data?

ie. what use case/bug would it solve?

mattab commented 10 years ago

Concerning the devicesDetection Plugin: I think it would be a never-ending uphill battle to try to maintain an always-up-to-date mapping of UA strings to devicePixelRatios

We only maintain regular expressions to detect devices, brands, models, etc. we don't maintain list of user agents, except of course in our extensive test suite which tests more than 1000 user agents after each commit. It will be a challenge to maintain this list for sure, but we call on the community to help us improve it over time and add new devices and models and brands and browsers and operating systems.

nkuehn commented 10 years ago

ok, I'll try to isolate the issue with the android resolutions tracked on a local installation.

Another possible cross-check whether this is actually a bug would be to take a real-world dataset (like the piwik forums and/or website) and segment some popular hi-res Android devices (from "device model" report, e.g. the GT - I9_5_0_5 against the screen resolutions tracked for them via the Javascript side of Piwik. If the resolution tracked for that Model is Full HD my bug description may be wrong because that's the way the iOS devices are tracked, too (real physical resolution).

I unfotunately don't have such a dataset yet because we're not yet live with piwik.

nkuehn commented 10 years ago

remove the underscores, I was fighting with the trac spam filter

mattab commented 10 years ago

ie. what use case/bug would it solve? we would need to know whether it is a bug or a new feature request, i'm not sure yet...

sgiehl commented 6 years ago

devicePixelRatio won't be considered at all anymore. See https://github.com/piwik/piwik/issues/10289 We maybe could start tracking the value of devicePixelRatio as separate value in the future and add an additional report showing calculated resolutions