In a previous article, we described how to save referral source information to understand where your most valuable users are coming from. In this article we will add one additional piece of information: the platform (device, browser, etc.) your users are working on. With this, you'll be able to understand how many users are actually logging in via mobile devices and how that affects LTV.
Every time a request is made to your website, the user’s browser sends a “User-Agent” string with information about the platform making the request. Here are some examples of the User-Agent string:
If you look closely, you will see that the string contains information about the user’s operating system, browser, and the name of the device they are using (if it has a name). Although User-Agent strings vary widely across platforms and even versions of the same platform, it is generally true that the platform name will exist somewhere within. For example, #1 above is a Mac with the Chrome browser, #2 above is a Windows machine with the Firefox browser, #3 is an iPhone, #4 is an iPad, and #5 is an Android device.
This information can be accessed by your server every time a request is made. In PHP, the User-Agent string is stored in
$_SERVER['HTTP_USER_AGENT']. In Ruby on Rails, it is stored in
request.env['HTTP_USER_AGENT']. Other languages and environments will allow you to access it in similar ways.
When should you record this data?
We suggest that you add a new field called “Platform” or “User-Agent” to your “Customers” and “Orders” database tables to store this information whenever a user is created or an order is placed. If you’re using a SQL database, this field should be a
VARCHAR(255) [note: the User-Agent string is allowed to be much longer than this, but in practice it rarely exceeds this length].
How do I parse out the useful segments?
There are a number of libraries out there to help you parse the user agent string into components like operating system, device, etc. The ua-parser project supports a number of different programming languages - check it out.
Armed with this new information, we can understand how users access our site, and possibly how our best users access it in different ways than others. We can then tailor our user experience or marketing for certain groups.