I’m looking to gather statistics on player devices, so we can see what OS/device people are playing on. So far, I’ve found that…
iOS devices can fairly reliably be detected using OS.get_model_name() and a lookup dictionary. They use identifiers like “iPhone 17,1”, which is the iPhone 16 Pro, etc.
Android seems to be trickier, maybe they return pretty good model names out of the box? I have no devices to test on.
Detecting desktop vs laptop seems tricky, except for MacOS - which has “MacBook” in the model name.
Windows desktop devices seem to just return the motherboard model.
So far, I’ve got a static class which tries to guess based on these things. I use a .json file with a bunch of iOS and android model names to look up.
Is there a best practice for detecting the device name?
Probably the most useful info you can get on a PC is:
OS.get_name() will tell you the OS
OS.get_memory_info() will do what it says on the tin
OS.get_processor_name() will also do what it says on the tin
OS.get_video_adapter_driver_info(), RenderingServer.get_video_adapter_name() etc for GPU
OS.has_feature() for other details
All of that said, do make sure you let people know you’re collecting info from their machines, and give them the opportunity to opt out. I know the tech industry is trying to train everyone to accept that software rooting around on your machine then phoning home is normal, but don’t help them do that.
I second what @hexgrid said, please reconsider this and only collect this if your game or your company ABSOLUTELY needs this and there’s no way around it. If it’s just out of curiosity, don’t even ask the user if they want to opt out. Have them opt out by default, and give them an option to opt in IF they want to.
Regardless of the ethics of the situation (and I agree with @hexgrid and @tibaverus) be aware that trying to detect any of that without the explicit permission of your users can get you banned on the Apple App Store, Google Play, the Microsoft Store, Steam and Itch. And once you’re banned, you’re banned. And since your accounts are tied to your real identity and banking information, it’s really hard to get unbanned. So be careful.
Having said that, there are shysty ways of getting around that such as TOS agreements that force the user to comply. Though keep in mind that laws and regulations are different in every country/locality - and those regulations apply to you if any of your users are in a locality. So for every market you’re in, you are responsible for knowing the rules and regulations.
If this is just curiosity so you know who your players are and what systems to focus on, detecting OS is pretty benign these days since every web browser does that to serve you pages. But beyond that, you are collecting analytical data, and you have to tell people what you are collecting and give them the chance to opt out - especially any EU users. (Their regulations pretty much drive privacy standards worldwide for web pages and apps.)
Thanks for the tips - I agree completely that user privacy should be prioritized, and we will follow all relevant EU regulations for sure. Any info we collect will also be anonymized so that even we can’t connect information to specific users.
That said, having some basic information like type of device (desktop, laptop, mobile, browser) is very useful as a developer or publisher. If it turns out 60% of users are playing on a device with an old CPU, we need to optimize for that, for example.
As for the original question of how to detect the device name; since making this post, I’ve learned that devices use varying model names:
Apple devices are straightforward, using device identifiers. For example “iPhone18,3” is an iPhone 17. “MacBookPro16,1” is the 16-inch MacBook Pro from 2019.
For Android devices, there’s no set standard - but you can find device identifiers for most of the popular ones (example; “SM-S921B” = Samsung Galaxy S23)
I ended up implementing a map of the most popular devices using a .json file as a lookup.
Other than device names, we can deduce some things based on the OS. MacBooks can be reliably determined whether it’s a laptop or desktop, but Windows and Linux is more tricky.