matomo-org / matomo-sdk-ios

Matomo iOS, tvOS and macOS SDK: a Matomo tracker written in Swift
MIT License
388 stars 164 forks source link

Device Model Name #347

Closed goelay closed 4 years ago

goelay commented 4 years ago

Hello, We are experience an issue where I am seeing seeing few model being reported as "Apple - iPhone" & "Apple - iPAD" instead of the device exact name.

Guiboune commented 4 years ago

Same here

brototyp commented 4 years ago

Hey, thanks for reporting. Do you have any details? Do you know if this any specific iOS version, or any specific devices where this happens?

goelay commented 4 years ago

Hey, It's not OS specific. We are not able to get info for specific device its occurring but its very easily replicable.

brototyp commented 4 years ago

So it's only happening for a few specific devices? Do you know which devices?

goelay commented 4 years ago

Its happening for majority of the devices I believe as per our analysis. We do not know the devices.

Screenshot 2020-09-16 at 3 40 22 PM
brototyp commented 4 years ago

Hm. That's interesting. Did that change appear along with an update of the SDK? Or maybe an update of the backend?

goelay commented 4 years ago

We are on latest version and we are seeing this issue from a long time so it's not related to version I suppose.

Findus23 commented 4 years ago

It would be great if you could check the server access log for user agents (ideally of those unspecific visits). That way you can check on https://devicedetector.lw1.at/ how Matomo detects that specific user agent and maybe check if some information about the exact device is missing there.

ghost commented 4 years ago

Hello,

I guess the issue is from the devicedetector.lw1.at because even if I go to this url from iPhone 8, it says only iPhone as model property.

Findus23 commented 4 years ago

@BastienLebrun That's another issue: Apple does intentionally not mention the exact device type in the user agents anymore for privacy reasons when browsing in Safari, so there is nothing for Matomo to detect.

But that should not affect the iOS SDK as there the user agent can be built by the SDK code.

brototyp commented 4 years ago

Hey @BastienLebrun, @goelay and @Guiboune, thanks a lot for the followup. In theory, the SDK does modify the user agent, so that it contains the actual device identifier, such as iPad3,6 instead of just iPhone.

To figure out where exactly the problem is: Do you use the latest version (7.2.2) of Matomo? If that's the case, can you please check out the branch over here, install it in your app and right after initializing the MatomoTracker add a matomoTracker.logger = DefaultLogger(minLevel: .verbose)? This should print something like MatomoTracker [V] Generated User Agent: Mozilla/5.0 (x86_64; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MatomoTracker SDK URLSessionDispatcher in the console. If you run this on a device that is not recognized on the server, we can figure out what the generated user agent is, and maybe that helps to get closer to the issue.

Findus23 commented 4 years ago

@brototyp You are right that the only way to specify the device in Matomo is the user agent. It will be parsed by https://github.com/matomo-org/device-detector which gives the results users can see in Matomo. For apple devices it uses the regex here: https://github.com/matomo-org/device-detector/blob/c495cee660e1e8113fdea7929c659dd6943aae4d/regexes/device/mobiles.yml#L477

On https://devicedetector.lw1.at/ you can test the output of the latest version (master branch), so it might slightly differ from the one shipped in Matomo, but it shouldn't matter here.

Unfortunately user agents have no defined format as every device sends what they think is right. With iOS devices it is easier as they all have the same schema and contain the internal name of the device (maybe you can get the same name programmatically).

The user agent

Mozilla/5.0 (x86_64; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MatomoTracker SDK URLSessionDispatcher

contains no info about the device, so there is nothing that could be detected.

BTW: Do you know if you currently still send iOS user agents for iPads? Safari sends a macOS user agent by default to get websites to display desktop sites. (https://github.com/matomo-org/device-detector/issues/6313)

brototyp commented 4 years ago

Thanks both of you for the feedback.

I think we need to rethink our UserAgent generation. Right now the SDK asks the WebView to generate the UserAgent and will then replace iPhone with the actual iPhone version. There are just to many issues with it:

I opened a PR that completely changes, how we generate the UserAgent. @BastienLebrun, @goelay and @Guiboune can you please have a look at it, to see if it works in your case?

brototyp commented 4 years ago

The latest release, version 7.3, contains a major update un user agent generation that should fix this issue. I will close this ticket for now. Please feel free to comment here, if it doesn't.