What is preferable : detecting device using its size or user agent string?

827 views Asked by At

I need to differentiate between mobile/tablet and desktop browsers and i was wondering is it better to parse user agent string or look at width and height of the device to determine same? Which method is preferable and why?

TIA

2

There are 2 answers

0
Rob Whiteside On

You typically need to do both. The User Agent isn't enough to distinguish between android phones and tablets.

See this link on how Google Web Toolkit does it: https://code.google.com/p/google-web-toolkit/source/browse/trunk/samples/mobilewebapp/src/com/google/gwt/sample/mobilewebapp/FormFactor.gwt.xml?r=10041

Basically, you check the useragent for "iphone" or "ipad", else check for "android" (if so, use the size to determine mobile/tablet), otherwise it's a "desktop".

0
SergeyB On

Is this information directly used by your application, or is it used by business/marketing to figure who is looking at your site? If it is a marketing need, then you should use Google Analytics, you simply embed a piece of code into your HTML and your business folks will get ALL the info they'd ever want about visitor's devices, browsing patterns, drop off pages, flows, etc.