diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad4634a..c06e746d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 5.1.2 +* **bugfix** Replaced generic phone model by device model. [#254](https://github.com/matomo-org/matomo-sdk-ios/pull/253) + ## 5.1.1 * **bugfix** Fixed Xcode build settings for Carthage support. [#224](https://github.com/matomo-org/matomo-sdk-ios/pull/244) (by @phranck) diff --git a/MatomoTracker/URLSessionDispatcher.swift b/MatomoTracker/URLSessionDispatcher.swift index 78322968..30fa4732 100644 --- a/MatomoTracker/URLSessionDispatcher.swift +++ b/MatomoTracker/URLSessionDispatcher.swift @@ -36,7 +36,16 @@ final class URLSessionDispatcher: Dispatcher { let currentUserAgent = webView.stringByEvaluatingJavaScript(from: "navigator.userAgent") ?? "" #elseif os(iOS) let webView = UIWebView(frame: .zero) - let currentUserAgent = webView.stringByEvaluatingJavaScript(from: "navigator.userAgent") ?? "" + var currentUserAgent = webView.stringByEvaluatingJavaScript(from: "navigator.userAgent") ?? "" + if let regex = try? NSRegularExpression(pattern: "\\((iPad|iPhone);", options: .caseInsensitive) { + let deviceModel = Device.makeCurrentDevice().platform + currentUserAgent = regex.stringByReplacingMatches( + in: currentUserAgent, + options: .withTransparentBounds, + range: NSRange(location: 0, length: currentUserAgent.count), + withTemplate: "(\(deviceModel);" + ) + } #elseif os(tvOS) let currentUserAgent = "" #endif