From 87683c7aa70c0700554996e968c22c29ed1a6a08 Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Tue, 18 Jun 2024 13:38:45 +0200 Subject: [PATCH] Add iOS machine name to user agent This allows matomo to figure out the exact iOS device (for example "iPhone 14 Pro Max") instead of just "iPhone". --- lib/src/matomo.dart | 3 ++- test/ressources/mock/data.dart | 1 + test/ressources/mock/mock.dart | 3 +++ test/src/matomo_test.dart | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/matomo.dart b/lib/src/matomo.dart index 091d5ec..505b7a1 100644 --- a/lib/src/matomo.dart +++ b/lib/src/matomo.dart @@ -385,8 +385,9 @@ class MatomoTracker { final systemName = iosInfo.systemName; final version = iosInfo.systemVersion; final model = iosInfo.model; + final machine = iosInfo.utsname.machine; - return '$systemName $version, $model'; + return '$systemName $version, $model $machine'; } else if (_platformInfo.isWindows) { final windowsInfo = await effectiveDeviceInfo.windowsInfo; final releaseId = windowsInfo.releaseId; diff --git a/test/ressources/mock/data.dart b/test/ressources/mock/data.dart index 4760d6d..1350067 100644 --- a/test/ressources/mock/data.dart +++ b/test/ressources/mock/data.dart @@ -150,6 +150,7 @@ const androidModel = 'androidModel'; const iosSystemName = 'iosSystemName'; const iosSystemVersion = 'iosSystemVersion'; const iosModel = 'iosModel'; +const iosMachine = 'iosMachine'; const windowsReleaseId = 'windowsReleaseId'; const windowsBuildNumber = 1; const macOsModel = 'macOsModel'; diff --git a/test/ressources/mock/mock.dart b/test/ressources/mock/mock.dart index 0853f2c..b708442 100644 --- a/test/ressources/mock/mock.dart +++ b/test/ressources/mock/mock.dart @@ -42,6 +42,8 @@ class MockAndroidBuildVersion extends Mock implements AndroidBuildVersion {} class MockIosDeviceInfo extends Mock implements IosDeviceInfo {} +class MockIosDeviceUtsname extends Mock implements IosUtsname {} + class MockWindowsDeviceInfo extends Mock implements WindowsDeviceInfo {} class MockMacOsDeviceInfo extends Mock implements MacOsDeviceInfo {} @@ -76,6 +78,7 @@ final mockWebBrowserInfo = MockWebBrowserInfo(); final mockAndroidDeviceInfo = MockAndroidDeviceInfo(); final mockAndroidBuildVersion = MockAndroidBuildVersion(); final mockIosDeviceInfo = MockIosDeviceInfo(); +final mockIosUtsname = MockIosDeviceUtsname(); final mockWindowsDeviceInfo = MockWindowsDeviceInfo(); final mockMacOsDeviceInfo = MockMacOsDeviceInfo(); final mockLinuxDeviceInfo = MockLinuxDeviceInfo(); diff --git a/test/src/matomo_test.dart b/test/src/matomo_test.dart index 395ecb5..d8ffbfc 100644 --- a/test/src/matomo_test.dart +++ b/test/src/matomo_test.dart @@ -303,6 +303,8 @@ void main() { when(() => mockIosDeviceInfo.systemName).thenReturn(iosSystemName); when(() => mockIosDeviceInfo.systemVersion).thenReturn(iosSystemVersion); when(() => mockIosDeviceInfo.model).thenReturn(iosModel); + when(() => mockIosDeviceInfo.utsname).thenReturn(mockIosUtsname); + when(() => mockIosUtsname.machine).thenReturn(iosMachine); // Windows when(() => mockDeviceInfoPlugin.windowsInfo) @@ -373,7 +375,7 @@ void main() { expect( userAgent, - '$iosSystemName $iosSystemVersion, $iosModel', + '$iosSystemName $iosSystemVersion, $iosModel $iosMachine', ); });