Ambiguous User-Agents and WURFL.js

Ambiguous User-Agents and WURFL.js

“Writing a really general parser is a major but different undertaking. By far, the hardest points being sensitivity to context and resolution of ambiguity.”

Graham Nelson by ScientiaMobile

While ScientiaMobile is the company with most experience in the field of Device Detection, there are some devices, or versions of devices, that are very difficult to accurately detect. An ambiguous User-Agent string is only a part of the challenge. Common feature detection techniques suffer the same challenge. Due to the high penetration of Apple devices, this is where we meet the challenge on a day to day basis.

For example, distinguishing an iPhone 5 from an iPhone 5S, or even distinguishing a 4S from a 6 Plus, is challenging by just looking at the User-Agent.

The specification of HTTP is pretty clear on the purpose of the User-Agent, but still device- and browser vendors make it difficult for developers to completely trust a User-Agent. This is due to historical reasons.  This is also why Device Detection solutions like WURFL are so important.

Let’s look at an example:

Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4

This is a User-Agent string from an iPhone running iOS 8.1, browsing with the Safari browser. Quite easy to see. But which iPhone? The official documentation from Apple doesn’t give us any more clues. Apple has stated that they want developers to care about two (three including the iPod) devices; the iPhone and the iPad, hence the ambiguous User-Agents. Whether this is right or wrong is a philosophical debate, but it is quite safe to argue that the iPhone 4S and iPhone 6 Plus are two very different devices because of their physical dimensions and end users would benefit from an adapted experience. But unfortunately, it is not possible.

The User-Agent above can be anything from a 4S to a 6 Plus. Any analytics tool on the market, based on User-Agent analysis alone, will simply report this as “Apple iPhone” due to Apple’s User-Agent policy.

Having said that, ScientiaMobile recently launched WURFL.js which combines User-Agent detection with client side feature detection in JavaScript. This combination allows us to distinctly detect all the versions of iPhone. This covers the full spectrum: from the very first iPhone, to the new iPhone 6 and 6 Plus. If you’re using Google Analytics, or any similar web analytics tool, here’s a guide on how to leverage WURFL.js for accurate Device Detection .

Even if both HTTP/1.0 and HTTP/1.1 specification is very clear on the purpose of the User-Agent string, vendors interpret it differently. Most vendors do a good enough job so that WURFL can identify the device and its capabilities. However, a few vendors, most notably Apple, makes it a bit more challenging. In these cases the User-Agent string alone is not enough.

ScientiaMobile takes detection accuracy very seriously, so we created WURFL.js to solve this problem. Now, our customers and mobile web community can use these tools to create the best possible user experience and generate the most reliable usage statistics.