User-Agent parsing allows you to identify devices accessing web content due to the fact that a User-Agent string conveys information to the server about the source of the request. If you’re looking for a simple and reliable way for parsing User-Agent strings, you’ve come to the right place. This article provides you with an overview of UA parsing and information on how to implement it.
Why User-Agent parsing is problematic
The User-Agent (UA) string is one of the headers defined in the HTTP standard which says that it’s generally used for identifying the origin of the request sent to the web server. The standard doesn’t really specify the details on how UAs should be built. Here’s what it says about requirements related to the UA field:
This excerpt highlights the fact that the rules for creating UAs are extremely superficial given that only vague “product tokens” are mentioned as possible components of a UA. In fact, browser makers and device manufacturers are free to conceal some important information or even build nonsensical UAs. Here is an example of a UA string which is sent by an IE Mobile browser used on a Windows Phone-based device:
There are many keywords included in this UA which aren’t related to a Windows Phone device or the IE Mobile browser, such as “Mozilla”, “Android”, “iPhone”, “Mac OS X”, or “Mobile Safari”.
The information included in the UA can’t be analyzed simply by searching for keywords because it will return inaccurate results. To accurately detect devices requesting online content, you need a sophisticated mechanism for parsing information included in the UA header that can actually detect patterns and look them up in a highly accurate, comprehensive, regularly updated device database.
User-Agent parsing using a dedicated API
The best option for businesses looking to implement a User-Agent parsing method is to use a dedicated third-party device detection platform, such as DeviceAtlas. This works especially well for high-traffic, high-profile websites and other online services such as ad platforms or web analytics tools.
You will usually have two options for a User-Agent parser including cloud-based and a locally-deployed solution.
1. Cloud-based User-Agent parsing
With cloud-based detection, device data is provided on-demand for device headers analyzed through the cloud API. To implement cloud-based detection in your website you need to drop a code snippet into your website’s code. The UA parsing service adds the capability of identifying and handling traffic from any device to your website via an up-to-date database of all the latest devices.
2. Locally-based User-Agent parsing
Some of the largest businesses avoid any dependency on cloud services, and thus utilize locally installed device detection platform.
To implement locally-installed detection you need to download a device data file from your detection provider and deploy the provider’s API in your environment. In DeviceAtlas’s case, the device data is available in a highly compressed JSON format minimizing the server footprint. It can either be downloaded manually or obtained via an automated script. The data file consists of a JSON structure offering extremely fast lookups with a minimal footprint.
You can check User-Agent parsing implementation examples here. It is best to set automatic downloads for the data file to ensure that device data is up-to-date.
Get started with a local device detection trial
DeviceAtlas is a high-speed device detection solution used by some of the largest companies in the online space to:
- Optimize UX and conversion rate on mobile
- Boost web performance
- Target ads and analyze web traffic
- Enable App analytics and advertising insights
Get started with a locally-installed trial to test DeviceAtlas at no cost.