Those answers will work fine until you want to separate tablets from mobiles. To get a better match you'll need something like Handset Detection (disclaimer : my startup) which can separate out devices by class (tablet/console/mobile). You can detect serverside with an API kit or on device with Javascript.