Search code examples
javascriptweb-applicationsgoogle-analyticsgoogle-analytics-apimobile-devices

How does Google Analytics determine “Device Category” (mobile/tablet/desktop)?


Currently, Google Analytics for web exposes a device category field, the discrete values for which are mobile, tablet, and desktop. The interface also allows you to dig deeper into the specific device it is. I imagine that Google has some kind of dictionary that maps these values to each other (device to device category, and/or vice versa), but I don’t know for sure.

Ultimately, I’d like to hook into this logic and utilize it. I’d like to run experiments based on the device category (i.e., mobile devices, in my case). There are lots of answers out there attempting to determine device category based on user agent and the like, but Google seems to have the most accurate eye into this. Thank you for your thoughts, in advance!


Solution

  • It is indeed from the User Agent Header which Google then analyzes to determine device, OS, and browser versions. Some things to point out:

    • The processing is done on the server side (Google) so there is no way of directly modifying that data (even when sending data via the measurement protocol).

    • The processing details are not disclosed by Google so you won't know what the outcome of your experiments are until they're reported by Google Analytics (which due to the 24-48 hour data processing latency might make such experimentation tedious).

    • Attempting to manipulate it might "break" your analytics: Google is vague about this, they just say: "Google has libraries to identify real user agents. Hand crafting your own agent could break at any time". 2 consequences I can think of: Google simply drops the traffic if it can't parse the User Agent OR marks it as bot/spider traffic (which will also be dropped if you have enabled the bot filtering option).

    Although it's not mentioned in the documentation, I also suspect Google to rely on other data points, which could be:

    Although over time the last one should be less and less relevant as support for progressively disappears.