2

I am currently working on an Android App that uses WebViews to load some pages (I cannot modify the HTML, because it is being used by the iOS App and the website). First we had the problem, that the user agent was the same for the InApp WebViews and a regular Android Browser (starting with Android 4.4 which started using chromium as the webengine).

InApp Webview Example:

Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.117 Mobile Safari/537.36

So in Google Analytics we could not differentiate between users using the App and users visiting the HTML page with the normal browser. The solution was to alter the Useragent String with:

webView.getSettings().setUserAgentString("Our custom Mobile Android InApp Browser");

This worked for Google Analytics.

But now we ran into the problem that Youtube is not identifying InApp users as mobile users and is serving the desktop Youtube player.

Now I am looking for one of the following solutions:

1) Somehow make Google Analytics identify the In-App-Browser as different from the normal Android Browser.

or

2) Have some custom String for the webview-user-agent that causes Youtube to serve its mobile version.

Thanks!

2 Answers 2

1
+50

Setting a custom User-Agent string seems like a good solution.

Just make sure this custom string can be recognized by Youtube as a mobile Android device. For example, you could use the "field" used to store the device model:

Dalvik/1.6.0 (Linux; U; Android 4.0.3; <Your_custom_marker> Build/IML74K)
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, it works to receive the Mobile Youtube Player, when it shows up properly on analytics, I will accept your answer. Do you know what the browser name will be in analytics?
This method will not change the browser name, but in Google Analytics, you can add Mobile Device Model as a secondary dimension of your reports. I'm not sure if it will recognize an unknown model name though.
Using your provided string causes Google Analytics to see it as Browser Version "Android Runtime", which up to now is unique for the app. Do you know when this string would be provided from any other devices?
stackoverflow ist telling me that i have to wait 22 more hours before i can award you the points
It's good news that Google Analytics seem to recognize this UA as a specific type of "browser" (I think the Dalvik part of the string is what matters here). FYI this is the kind of user-agent string that is sent by my own app (I use simple HTTP requests, not webviews). There is no absolute guarantee but I think you are safe in assuming that no real browser will be put in this same category.
0

Try this in your web frontend code:

Boolean(window?.ReactNativeWebView);

This would help you differentiate between them easily.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.