Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improves detection for Apple devices and iOS, iPadOS #7744

Merged
merged 21 commits into from
Jul 19, 2024

Conversation

liviuconcioiu
Copy link
Collaborator

No description provided.

@liviuconcioiu
Copy link
Collaborator Author

@sanchezzzhak can you double check the names please? https://gist.github.com/adamawolf/3048717, theapplewiki, everymac report different names. Thanks!

@sanchezzzhak
Copy link
Collaborator

script compare

<?php

use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\AbstractParser;

include __DIR__ . '/../vendor/autoload.php';

AbstractParser::setVersionTruncation(AbstractParser::VERSION_TRUNCATION_NONE);

$fixtureFiles = array_merge(
    glob(__DIR__ . '/../Tests/fixtures/*.yml'),
    glob(__DIR__ . '/../Tests/Parser/Client/fixtures/*.yml'),
    glob(__DIR__ . '/../Tests/Parser/Device/fixtures/*.yml')
);

$compareListUrl = 'https://raw.githubusercontent.com/fieldnotescommunities/ios-device-identifiers/master/ios-device-identifiers.json';
$compareList = json_decode(file_get_contents($compareListUrl), true);

$regexes = [
    # Iphone for x-ucbrowser-ua
    [
        'regex' =>  'dv\(iPh([^)]+)\);pr\(UCBrowser/',
        'name' => 'iPhone$1',
    ],
    # iPhone/iPad/iPod/Watch code devices
    [
        'regex' => '[\(, ](iP(?:hone|[ao]d)|Watch)(\d{1,2}),(\d{1,2})[;\]]',
        'name' => '$1$2,$3',
    ],
    // # MS Office Apple
    [
        'regex' => '(?:Non)?AppStore; Apple/(.*?)\)',
        'name' => '$1$2,$3',
    ],
];

function buildByMatch(string $item, array $matches): string
{
    $search  = [];
    $replace = [];

    for ($nb = 1; $nb <= \count($matches); $nb++) {
        $search[]  = '$' . $nb;
        $replace[] = $matches[$nb] ?? '';
    }

    return \trim(\str_replace($search, $replace, $item));
}



$matomoList = [];
foreach ($fixtureFiles as $file) {
    foreach (Spyc::YAMLLoad(file_get_contents($file)) as $i => $fixture) {
        $useragent = $fixture['user_agent'];
        $brand = $fixture['device']['brand'] ?? '';
        $model = $fixture['device']['model'] ?? '';
        $isApple = $brand === 'Apple';

        $result = null;

        if ($isApple) {
            $code = null;
            foreach ($regexes as $regex){
                if (preg_match("#{$regex['regex']}#i", $useragent, $matches)) {
                    $code = buildByMatch($regex['name'], $matches);
                    $matomoList[strtolower($code)] = $model;
                    break;
                }
            }
        }

    }
}
$std = fopen("php://output", 'r+');
fputcsv($std, ['Code', 'Compare Name', 'Matomo Name'], ',', '"');
foreach ($compareList as $compareCode => $compareName) {
    $code = strtolower($compareCode);
    $matomoName = $matomoList[$code] ?? '';

    $deviceDetector = new DeviceDetector('  ' . $compareCode);
    $deviceDetector->parse();

    if ($matomoName !== '') {
        unset($matomoList[$code]);
    }
    $data = [
        $code, $compareName, $matomoName, $deviceDetector->getModel()
    ];
    fputcsv($std, $data);
}

fwrite($std, PHP_EOL);
fwrite($std, PHP_EOL);

if (count($matomoList) > 0) {
    foreach ($matomoList as $compareCode => $compareName) {
        $code = strtolower($compareCode);
    }
    $data = [
        $code, '', $matomoName, '',

    ];
    fputcsv($std, $data);
}

result

C1 C2 C3 C4
Code Compare Name Matomo Name Simulate detect
iphone1,1 iPhone 1st Gen null iPhone
iphone1,2 iPhone 3G 2nd Gen null iPhone 3G
iphone2,1 iPhone 3GS 3rd Gen null iPhone 3GS
iphone3,1 iPhone 4 null iPhone 4
iphone3,2 iPhone 4 (GSM) Rev A null iPhone 4
iphone3,3 iPhone 4 (CDMA) null iPhone 4
iphone4,1 iPhone 4s null iPhone 4S
iphone5,1 iPhone 5 (GSM) iPhone 5 iPhone 5
iphone5,2 iPhone 5 (CDMA+LTE) iPhone 5 iPhone 5
iphone5,3 iPhone 5c (GSM) iPhone 5C iPhone 5C
iphone5,4 iPhone 5c (Global) iPhone 5C iPhone 5C
iphone6,1 iPhone 5s (GSM) null iPhone 5S
iphone6,2 iPhone 5s (Global) null iPhone 5S
iphone7,1 iPhone 6 Plus null iPhone 6 Plus
iphone7,2 iPhone 6 iPhone 6 iPhone 6
iphone8,1 iPhone 6s null iPhone 6s
iphone8,2 iPhone 6s Plus null iPhone 6s Plus
iphone8,4 iPhone SE null iPhone SE
iphone9,1 iPhone 7 iPhone 7 iPhone 7
iphone9,2 iPhone 7 Plus null iPhone 7 Plus
iphone9,3 iPhone 7 (no CDMA) null iPhone 7
iphone9,4 iPhone 7 Plus (no CDMA) iPhone 7 Plus iPhone 7 Plus
iphone10,1 iPhone 8 null iPhone 8
iphone10,2 iPhone 8 Plus iPhone 8 Plus iPhone 8 Plus
iphone10,3 iPhone X null iPhone X
iphone10,4 iPhone 8 (no CDMA) iPhone 8 iPhone 8
iphone10,5 iPhone 8 Plus (no CDMA) null iPhone 8 Plus
iphone10,6 iPhone X (no CDMA) iPhone X iPhone X
iphone11,2 iPhone XS iPhone XS iPhone XS
iphone11,4 iPhone XS Max (China) null iPhone XS Max
iphone11,6 iPhone XS Max null iPhone XS Max
iphone11,8 iPhone XR iPhone XR iPhone XR
iphone12,1 iPhone 11 iPhone 11 iPhone 11
iphone12,3 iPhone 11 Pro iPhone 11 Pro iPhone 11 Pro
iphone12,5 iPhone 11 Pro Max iPhone 11 Pro Max iPhone 11 Pro Max
iphone12,8 iPhone SE 2nd Gen null iPhone SE (2020)
iphone13,1 iPhone 12 mini null iPhone 12 Mini
iphone13,2 iPhone 12 iPhone 12 iPhone 12
iphone13,3 iPhone 12 Pro iPhone 12 Pro iPhone 12 Pro
iphone13,4 iPhone 12 Pro Max iPhone 12 Pro Max iPhone 12 Pro Max
iphone14,2 iPhone 13 Pro iPhone 13 Pro iPhone 13 Pro
iphone14,3 iPhone 13 Pro Max null iPhone 13 Pro Max
iphone14,4 iPhone 13 mini null iPhone 13 Mini
iphone14,5 iPhone 13 null iPhone 13
iphone14,6 iPhone SE 3rd Gen null iPhone SE (2022)
iphone14,7 iPhone 14 null iPhone 14
iphone14,8 iPhone 14 Plus iPhone 14 Plus iPhone 14 Plus
iphone15,2 iPhone 14 Pro iPhone 14 Pro iPhone 14 Pro
iphone15,3 iPhone 14 Pro Max iPhone 14 Pro Max iPhone 14 Pro Max
iphone15,4 iPhone 15 null iPhone 15
iphone15,5 iPhone 15 Plus null iPhone 15 Plus
iphone16,1 iPhone 15 Pro null iPhone 15 Pro
iphone16,2 iPhone 15 Pro Max null iPhone 15 Pro Max
ipod1,1 iPod 1st Gen null iPod Touch 1G
ipod2,1 iPod 2nd Gen null iPod Touch 2G
ipod3,1 iPod 3rd Gen null iPod Touch 3
ipod4,1 iPod 4th Gen null iPod Touch 4
ipod5,1 iPod 5th Gen iPod Touch 5 iPod Touch 5
ipod7,1 iPod 6th Gen iPod Touch 6 iPod Touch 6
ipod9,1 iPod 7th Gen null iPod Touch 7
ipad1,1 iPad 1st Gen (WiFi) null iPad
ipad1,2 iPad 1st Gen (3G) null iPad
ipad2,1 iPad 2nd Gen (WiFi) iPad 2 iPad 2
ipad2,2 iPad 2nd Gen (GSM) null iPad 2
ipad2,3 iPad 2nd Gen (CDMA) null iPad 2
ipad2,4 iPad 2nd Gen New Revision null iPad 2
ipad2,5 iPad mini 1st Gen (WiFi) iPad Mini iPad Mini
ipad2,6 iPad mini 1st Gen (GSM+LTE) null iPad Mini
ipad2,7 iPad mini 1st Gen (CDMA+LTE) null iPad Mini
ipad3,1 iPad 3rd Gen (WiFi) null iPad 3
ipad3,2 iPad 3rd Gen (CDMA) null iPad 3
ipad3,3 iPad 3rd Gen (GSM) null iPad 3
ipad3,4 iPad 4th Gen (WiFi) null iPad 4
ipad3,5 iPad 4th Gen (GSM+LTE) null iPad 4
ipad3,6 iPad 4th Gen (CDMA+LTE) iPad 4 iPad 4
ipad4,1 iPad Air 1st Gen (WiFi) null iPad Air
ipad4,2 iPad Air 1st Gen (GSM+CDMA) iPad Air iPad Air
ipad4,3 iPad Air 1st Gen (China) null iPad Air
ipad4,4 iPad mini 2nd Gen (WiFi) null iPad Mini 2
ipad4,5 iPad mini 2nd Gen (WiFi+Cellular) null iPad Mini 2
ipad4,6 iPad mini 2nd Gen (China) null iPad Mini 2
ipad4,7 iPad mini 3rd Gen (WiFi) null iPad Mini 3
ipad4,8 iPad mini 3rd Gen (WiFi+Cellular) null iPad Mini 3
ipad4,9 iPad mini 3rd Gen (China) null iPad Mini 3
ipad5,1 iPad mini 4th Gen (WiFi) null iPad Mini 4
ipad5,2 iPad mini 4th Gen (WiFi+Cellular) iPad Mini 4 iPad Mini 4
ipad5,3 iPad Air 2 (WiFi) iPad Air 2 iPad Air 2
ipad5,4 iPad Air 2 (WiFi+Cellular) null iPad Air 2
ipad6,3 iPad Pro 1st Gen (9.7 inch, WiFi) iPad Pro 9.7 iPad Pro 9.7
ipad6,4 iPad Pro 1st Gen (9.7 inch, WiFi+Cellular) iPad Pro 9.7 iPad Pro 9.7
ipad6,7 iPad Pro 1st Gen (12.9 inch, WiFi) iPad Pro 12.9 iPad Pro 12.9
ipad6,8 iPad Pro 1st Gen (12.9 inch, WiFi+Cellular) iPad Pro 12.9 iPad Pro 12.9
ipad6,11 iPad 5th Gen (WiFi) iPad 5 9.7 iPad 5 9.7
ipad6,12 iPad 5th Gen (WiFi+Cellular) null iPad 5 9.7
ipad7,1 iPad Pro 2nd Gen (12.9 inch, WiFi) null iPad Pro 2 12.9
ipad7,2 iPad Pro 2nd Gen (12.9 inch, WiFi+Cellular) null iPad Pro 2 12.9
ipad7,3 iPad Pro 2nd Gen (10.5 inch, WiFi) iPad Pro 10.5 iPad Pro 10.5
ipad7,4 iPad Pro 2nd Gen (10.5 inch, WiFi+Cellular) null iPad Pro 10.5
ipad7,5 iPad 6th Gen (WiFi) iPad 6 9.7 iPad 6 9.7
ipad7,6 iPad 6th Gen (WiFi+Cellular) null iPad 6 9.7
ipad7,11 iPad 7th Gen (WiFi) null iPad 7 10.2
ipad7,12 iPad 7th Gen (WiFi+Cellular) iPad 7 10.2 iPad 7 10.2
ipad8,1 iPad Pro 3rd Gen (11 inch, WiFi) null iPad Pro 3 11.0 WiFi
ipad8,2 iPad Pro 3rd Gen (11 inch, WiFi, 1TB) null iPad Pro 3 11.0 WiFi
ipad8,3 iPad Pro 3rd Gen (11 inch, WiFi+Cellular) null iPad Pro 3 11.0
ipad8,4 iPad Pro 3rd Gen (11 inch, WiFi+Cellular, 1TB) null iPad Pro 3 11.0
ipad8,5 iPad Pro 3rd Gen (12.9 inch, WiFi) null iPad Pro 3 12.9
ipad8,6 iPad Pro 3rd Gen (12.9 inch, WiFi, 1TB) null iPad Pro 3 12.9
ipad8,7 iPad Pro 3rd Gen (12.9 inch, WiFi+Cellular) null iPad Pro 3 12.9
ipad8,8 iPad Pro 3rd Gen (12.9 inch, WiFi+Cellular, 1TB) null iPad Pro 3 12.9
ipad8,9 iPad Pro 4th Gen (11 inch, WiFi) null iPad Pro 2 11"
ipad8,10 iPad Pro 4th Gen (11 inch, WiFi+Cellular) null iPad Pro 2 11"
ipad8,11 iPad Pro 4th Gen (12.9 inch, WiFi) null iPad Pro 4 12.9"
ipad8,12 iPad Pro 4th Gen (12.9 inch, WiFi+Cellular) null iPad Pro 4 12.9"
ipad11,1 iPad mini 5th Gen (WiFi) null iPad Mini 5
ipad11,2 iPad mini 5th Gen (WiFi+Cellular) null iPad Mini 5
ipad11,3 iPad Air 3rd Gen (WiFi) null iPad Air 3
ipad11,4 iPad Air 3rd Gen (WiFi+Cellular) null iPad Air 3
ipad11,6 iPad 8th Gen (WiFi) null iPad 8 10.2"
ipad11,7 iPad 8th Gen (WiFi+Cellular) null iPad 8 10.2"
ipad12,1 iPad 9th Gen (WiFi) null iPad 9 10.2" WiFi
ipad12,2 iPad 9th Gen (WiFi+Cellular) null iPad 9 10.2"
ipad13,1 iPad Air 4th Gen (WiFi) null iPad Air 4 WiFi
ipad13,2 iPad Air 4th Gen (WiFi+Cellular) null iPad Air 4
ipad13,4 iPad Pro 3rd Gen (11 inch, WiFi) null iPad Pro 3 11" WiFi
ipad13,5 iPad Pro 3rd Gen (11 inch, WiFi) null iPad Pro 3 11"
ipad13,6 iPad Pro 3rd Gen (11 inch, WiFi+Cellular) null iPad Pro 3 11"
ipad13,7 iPad Pro 3rd Gen (11 inch, WiFi+Cellular) null iPad Pro 3 11"
ipad13,8 iPad Pro 5th Gen (12.9 inch, WiFi) null iPad Pro 5 12.9" WiFi
ipad13,9 iPad Pro 5th Gen (12.9 inch, WiFi) null iPad Pro 5 12.9"
ipad13,10 iPad Pro 5th Gen (12.9 inch, WiFi+Cellular) null iPad Pro 5 12.9"
ipad13,11 iPad Pro 5th Gen (12.9 inch, WiFi+Cellular) null iPad Pro 5 12.9"
ipad13,16 iPad Air 5th Gen (WiFi) null iPad Air 5 WiFi
ipad13,17 iPad Air 5th Gen (WiFi+Cellular) null iPad Air 5
ipad13,18 iPad 10th Gen null iPad Air 4 WiFi
ipad13,19 iPad 10th Gen null iPad Air 4 WiFi
ipad14,1 iPad mini 6th Gen (WiFi) null iPad Mini 6 WiFi
ipad14,2 iPad mini 6th Gen (WiFi+Cellular) null iPad Mini 6
ipad14,3 iPad Pro 4th Gen (11 inch) null iPad
ipad14,4 iPad Pro 4th Gen (11 inch) null iPad
ipad14,5 iPad Pro 6th Gen (12.9 inch) null iPad
ipad14,6 iPad Pro 6th Gen (12.9 inch) null iPad
watch1,1 Apple Watch 1st Gen 38mm case null null
watch1,2 Apple Watch 1st Gen 42mm case Watch 42mm null
watch2,6 Apple Watch Series 1 38mm case null null
watch2,7 Apple Watch Series 1 42mm case null null
watch2,3 Apple Watch Series 2 38mm case null null
watch2,4 Apple Watch Series 2 42mm case null null
watch3,1 Apple Watch Series 3 38mm case (GPS+Cellular) null null
watch3,2 Apple Watch Series 3 42mm case (GPS+Cellular) null null
watch3,3 Apple Watch Series 3 38mm case (GPS) null null
watch3,4 Apple Watch Series 3 42mm case (GPS) null null
watch4,1 Apple Watch Series 4 40mm case (GPS) null null
watch4,2 Apple Watch Series 4 44mm case (GPS) null null
watch4,3 Apple Watch Series 4 40mm case (GPS+Cellular) null null
watch4,4 Apple Watch Series 4 44mm case (GPS+Cellular) null null
watch5,1 Apple Watch Series 5 40mm case (GPS) null null
watch5,2 Apple Watch Series 5 44mm case (GPS) null null
watch5,3 Apple Watch Series 5 40mm case (GPS+Cellular) null null
watch5,4 Apple Watch Series 5 44mm case (GPS+Cellular) null null
watch5,9 Apple Watch SE 40mm case (GPS) null null
watch5,10 Apple Watch SE 44mm case (GPS) null null
watch5,11 Apple Watch SE 40mm case (GPS+Cellular) null null
watch5,12 Apple Watch SE 44mm case (GPS+Cellular) null null
watch6,1 Apple Watch Series 6 40mm case (GPS) null null
watch6,2 Apple Watch Series 6 44mm case (GPS) Watch Series 6 44mm null
watch6,3 Apple Watch Series 6 40mm case (GPS+Cellular) Watch Series 6 40mm null
watch6,4 Apple Watch Series 6 44mm case (GPS+Cellular) Watch Series 6 44mm null
watch6,6 Apple Watch Series 7 41mm case (GPS) null null
watch6,7 Apple Watch Series 7 45mm case (GPS) null null
watch6,8 Apple Watch Series 7 41mm case (GPS+Cellular) null null
watch6,9 Apple Watch Series 7 45mm case (GPS+Cellular) null null
watch6,10 Apple Watch SE 40mm case (GPS) Watch SE (Gen 2) 40mm null
watch6,11 Apple Watch SE 44mm case (GPS) Watch SE (Gen 2) 44mm null
watch6,12 Apple Watch SE 40mm case (GPS+Cellular) Watch SE (Gen 2) 40mm null
watch6,13 Apple Watch SE 44mm case (GPS+Cellular) Watch SE (Gen 2) 44mm null
watch6,14 Apple Watch Series 8 41mm case (GPS) Watch Series 8 41mm null
watch6,15 Apple Watch Series 8 45mm case (GPS) Watch Series 8 45mm null
watch6,16 Apple Watch Series 8 41mm case (GPS+Cellular) Watch Series 8 41mm null
watch6,17 Apple Watch Series 8 45mm case (GPS+Cellular) Watch Series 8 45mm null
watch6,18 Apple Watch Ultra Watch Ultra null
watch7,1 Apple Watch Series 9 41mm case (GPS) Watch Series 9 41mm null
watch7,2 Apple Watch Series 9 45mm case (GPS) Watch Series 9 45mm null
watch7,3 Apple Watch Series 9 41mm case (GPS+Cellular) Watch Series 9 41mm null
watch7,4 Apple Watch Series 9 45mm case (GPS+Cellular) Watch Series 9 45mm null
watch7,5 Apple Watch Ultra 2 Watch Ultra 2 null
null null null null
null null null null

@liviuconcioiu
Copy link
Collaborator Author

Thanks for the script! I've added 4 missing models. Also, you should update it, because the original is fetched from https://gist.github.com/adamawolf/3048717/

@sanchezzzhak sanchezzzhak merged commit a118d08 into matomo-org:master Jul 19, 2024
15 checks passed
@liviuconcioiu liviuconcioiu deleted the apple branch July 19, 2024 13:08
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants