A few months ago I watched a great talk from the Chrome Dev Summit about performance in slow devices.
It blew my mind all the work done by Facebook in identifying devices to create a better user experience. Fast-forward to now, and I've decided to study a bit more about the topic and see what I can do at Thinkific (the company I work for).
User agents
User agents are well-known by developers. We use them to detect bots, redirect users to a specific version of our website or append CSS classes on our page so we can create different experiences.
At Thinkific we already use the browser Ruby gem to parse the user-agent and get relevant info (bot detection for instance). So, I decided to persist the main info in a visitor_device table – here is the schema:
tenant_id: the course creator school the visitor is checking raw: the raw ua type: desktop / mobile / tablet / bot / other browser_name browser_version platform_name platform_version hardware: hstore containing memory, processor, device_model, device_name connection: hstore containing downlink_max, connection_type |
You probably noticed that a few things there are not available in the UA string. Time for new JavaScript APIs:
Getting hardware info using JavaScript
As covered in the Chrome Dev Summit video, we can use JS to get this info.
Memory
navigator.deviceMemory
will return a floating-point number. There are things to consider here:
- It only works over HTTPS
- Support is quite limited (Chrome only basically)
More about it:
Processors
navigator.hardwareConcurrency
will return the number of logical cores of the user’s CPU. Support for this is decent.
Detecting connection info using JavaScript
navigator.connection
is a new API containing information about the system’s connection, such as the current bandwidth of the user’s device or whether the connection is metered. The support is quite limited (Chrome only basically) but things are promising.
More about it:
Detecting the device model
The user agent may return some information about the model name. userstack is a service that gives you information based on the user agent. It works well and it is easy to integrate, however, depending on your needs, they can’t help.
Take for instance iDevices. Their user agent is basically the same so you can’t differentiate an iPad Pro from an old iPad that runs the last iOS. For these cases, you may need a better detection based on resolution, pixel density and other hardware information exposed in the browser. I did some quick research on this and found 3 products so far: WURFL.io, DeviceAtlas and 51Degrees. I haven’t had time to try their products yet, but I am looking forward to doing it (and posting about it)
FAQ
Question: Why not use Google Analytics / Mixpanel / Kibana / New Relic / your tool here?
We could get browser info inside other tools. But as a SaaS product we don’t use our own Google Analytics property (customers add their own). Also, adblockers may block these third-party tools. Last but not least, by having this info in our side we can adapt better.
Question: Do you have a list of low-end/high-end devices?
No. Maybe this can be built combining the number of processors and memory but I didn’t invest much time on this. In this project, my colleague created a Rails helper that would determine if the user would use the lite or default version of a website based on hardware. On this topic, it is important to mention that Facebook has a library for Android called Device Year Class.
Also posted on my blog. If you like this content, follow me on Twitter and GitHub.
By the way - Thinkific is hiring for several positions if you are interested.