Skip to content

Commit

Permalink
Add iOS machine name to user agent
Browse files Browse the repository at this point in the history
This allows matomo to figure out the exact iOS device (for example "iPhone 14 Pro Max") instead of just "iPhone".
  • Loading branch information
kuhnroyal committed Jun 18, 2024
1 parent 362721c commit 87683c7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/src/matomo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/ressources/mock/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 3 additions & 0 deletions test/ressources/mock/mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion test/src/matomo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -373,7 +375,7 @@ void main() {

expect(
userAgent,
'$iosSystemName $iosSystemVersion, $iosModel',
'$iosSystemName $iosSystemVersion, $iosModel $iosMachine',
);
});

Expand Down

0 comments on commit 87683c7

Please sign in to comment.