I've created a relatively simply library for pushing events to Google Analytics from a Xamarin Forms app using their Measurement Protocol API. The library works and events get logged to the GA account just fine.
One area that I need to improve is the "device type" reporting. GA uses the User Agent from the API requests to determine loads of stuff about the device - OS, platform, resolution, manufacturer, etc. If I was using a browser to make the calls, then obviously I'd get all of that, but since I'm using a basic HttpClient
there's no default user agent string.
I need to either store a large dictionary of possible strings (not a great idea), build up a string (an OK idea, except you have to do a load of introspection to get detailed), or have some way to ask the device itself what it uses for a user agent string.
If I have to build my own, what I'd like to do to start with is to be able to identify the OS (Android, iOS, Windows) that I'm on as well as the device type (tablet, phone). Sure, device manufacturer, model, etc would all be great, but building that lookup myself would get insane quickly.
I can find no clear documentation on how GA parses the user agent string, so I'm not completely clear on what the general form would look like to identify myself.
I've already found the long lists of user agent string online. What I'm hoping for is some sort of algorithm or documentation that might assist in generating at least a rudimentary user agent string that would allow a library consumer to report some basic device info that would in turn show up in their GA dashboards
EDIT
I suppose I should mention that ideally I'd have a PCL way of doing this. Right now the library is fully PCL and if I can avoid generating platform-specific implementations that would be great. Not a hard requirement, but a real "nice to have".