Skip to content Skip to sidebar Skip to footer

Correct Way To Format User-agent String In An Android Webview App?

In my android web app I want to modify my user agent so that I can identify it on my server and on google analytics. Currently the user-agent looks like this: Mozilla/5.0 (Linux; A

Solution 1:

Thanks to this blog, I found the answer. You should append the "Browser" and "Browser version" to the WebView's existing user-agent string and google analytics will pick it up.

Code:

WebSettings webSettings = webView.getSettings();
String userAgent = String.format("%s [%s/%s]", webSettings.getUserAgentString(), "App Android", BuildConfig.VERSION_NAME);
webSettings.setUserAgentString(userAgent);

In Google Analytics the "Browser" dimension value is "App Android" and "Browser Version" is the string in your build config.

Post a Comment for "Correct Way To Format User-agent String In An Android Webview App?"