Question

I need a way to detect and record the browser and version the client is using when visiting my site. I was wondering what the best way of doing this is. I am using MVC.net on the server end and JQuery 1.9+ and Modernizer for the client side.

Looking around I saw a butch of posts that were really old and possibly outdated (FF versions 3 and 4 era questions) and the rest said to not worry about detecting the browsers and to detect features instead. The problem is, The company I work for wants to store this data in a database, so feature detection isn't really a solution. Also doing some reading JQuery 1.9+ does not support the .browser() method anymore and you need to use the Jquery.support or add Jquery.migrate plugin.

I'm wanting to know the easiest, lightest weight, (and Modern?) way to accurately detect all major browsers/versions. Client or Server Side is fine...although Im pretty sure client side is more reliable.

Was it helpful?

Solution

The advice you read about using feature detection and not browser detection is absolutely right that if you are thinking of using the browser detection to make the site work differently in different browsers (or try to make it work the same).

But there are, as you've said, perfectly legitimate reasons for wanting to record the browser information.

The most obvious answer to this is to use the User Agent string. This is a string that the browser sends as part of the HTTP headers to identify itself.

All requests made to your site will be logged in your server logs. This will include the User Agent string that the browser provided.

There are a number of good analytics products available that can process the server logs and produce statistics on the browsers being used, pages being accessed, and a lot of other data. This is what I would recommend for you. If you go down this route, there is no need for you to do any extra code at all; it is purely a case of using an existing tool to read the logs. You can read about several possible tools for this job here: http://en.wikipedia.org/wiki/List_of_web_analytics_software

The one thing to bear in mind here is that the User Agent string is known not be a fully reliable source of information. It is provided by the browser, and can thus be changed by the user. Some browsers allow users to change them to anything they like. Some will pretend to be other browsers or other browser versions. And some are blanked out entirely by proxies, etc.

However, it's probably about as good as it gets.

It is theoretically possible to pin down more accurate details about the users' browsers using some sneaky Javascript tricks, but it is complex and likely to run foul of malware detectors, so I'd avoid going down that route. Just stick with the User Agent string in the server logs, and you'll be fine.

hope that hepls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top