i've created relatively library pushing events google analytics xamarin forms app using measurement protocol api. library works , events logged ga account fine.
one area need improve "device type" reporting. ga uses user agent api requests determine loads of stuff device - os, platform, resolution, manufacturer, etc. if using browser make calls, i'd of that, since i'm using basic httpclient
there's no default user agent string.
i need either store large dictionary of possible strings (not great idea), build string (an ok idea, except have load of introspection detailed), or have way ask device uses user agent string.
if have build own, i'd start able identify os (android, ios, windows) i'm on device type (tablet, phone). sure, device manufacturer, model, etc great, building lookup myself insane quickly.
i can find no clear documentation on how ga parses user agent string, i'm not clear on general form identify myself.
i've found long lists of user agent string online. i'm hoping sort of algorithm or documentation might assist in generating @ least rudimentary user agent string allow library consumer report basic device info in turn show in ga dashboards
edit
i suppose should mention ideally i'd have pcl way of doing this. right library pcl , if can avoid generating platform-specific implementations great. not hard requirement, real "nice have".
ios uiwebview (non-visual end-user):
var webview = new uiwebview(cgrect.empty); var useragentstring = webview.evaluatejavascript("navigator.useragent"); webview.dispose(); console.writeline(useragentstring);
note: once , store results future use creating uiwebview
, running javascript not cheap (perf wise)
sample output:
mozilla/5.0 (iphone; cpu iphone os 9_3 mac os x) applewebkit/601.1.46 (khtml, gecko) mobile/13e230
android java system:
var useragentstring = java.lang.javasystem.getproperty("http.agent"); log.debug("ua", useragentstring);
sample output:
dalvik/2.1.0 (linux; u; android 5.1.1; z716bl build/lmy47v)
note: if interested in creating own user-agent, should @ answer pulled code asop source.
i @ wikipedia link formatting , links rfc 1945
Comments
Post a Comment