-
Notifications
You must be signed in to change notification settings - Fork 489
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
Detect notebook devices in Facebook useragents #6346
Conversation
Adds detection for multiple notebooks
type: browser | ||
name: Mobicip | ||
short_name: MO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the app store, this is a utility for parental control.
https://apps.apple.com/us/app/mobicip-parental-control-app/id299153586
Mobicip is the easiest way to block websites, schedule screen time, restrict apps & videos, turn off games, track your kid’s location, and limit texting apps.
It is better to change the client type to app
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you do that in a new PR? Mobicip
wasn't added in this PR, so be good not to change that here
@@ -109,5 +111,7 @@ function format($str, $length) | |||
format($deviceTypes[8], $parsedUAs), getPercentage($deviceTypes[8], $parsedUAs), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's improve here, we can do it universally
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
require_once(__DIR__ . '/../vendor/autoload.php');
if (php_sapi_name() !== 'cli') {
die("web not supported");
}
if (count($argv) != 2) {
die("invalid arguments. Useage: php statistics.php filetoparse.txt");
}
use \DeviceDetector\Parser\Device\DeviceParserAbstract;
use DeviceDetector\DeviceDetector;
$deviceAvailableDeviceTypes = array_flip(DeviceParserAbstract::getAvailableDeviceTypes());
$parsedUAs = $unknownDeviceTypes =
$detectedBots = 0;
DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE);
$deviceTypes = (array_fill(0, count($deviceAvailableDeviceTypes), 0));
$startTime = microtime(true);
$handle = @fopen($argv[1], "r");
$parser = new DeviceDetector();
if ($handle) {
while (($line = fgets($handle, 4096)) !== false) {
if (empty($line)) {
continue;
}
if ($parsedUAs > 0 && $parsedUAs % 80 == 0) {
echo " $parsedUAs\n";
}
$parser->setUserAgent(trim($line));
$parser->parse();
echo '.';
$parsedUAs++;
if ($parser->isBot()) {
$detectedBots++;
continue;
}
if ($parser->getDevice() !== null) {
$deviceTypes[$parser->getDevice()]++;
} else {
$unknownDeviceTypes++;
}
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
$timeElapsed = microtime(true) - $startTime;
function getPercentage($cur, $max)
{
return format(round($cur * 100 / $max), ' ');
}
function format($str, $length)
{
return sprintf("%" . strlen($length) . "d", $str);
}
$line = "----------------------------------------------\n";
$mask = "%24s %10s (%s%s) \n";
$reportStat = [];
$reportStat[] = sprintf($mask, 'Type', 'Count', 'Percent', '');
$reportStat[] = $line;
foreach ($deviceTypes as $deviceTypeId => $deviceCount) {
$reportStat[] = sprintf(
$mask,
sprintf('%s:',mb_convert_case($deviceAvailableDeviceTypes[$deviceTypeId], MB_CASE_TITLE)),
format($deviceCount, $parsedUAs),
trim(getPercentage($deviceCount, $parsedUAs)),
'%'
);
}
$reportStat[] = sprintf(
$mask,
'Unknown',
format($unknownDeviceTypes, $parsedUAs),
trim(getPercentage($unknownDeviceTypes, $parsedUAs)),
'%'
);
$reportStat[] = $line;
echo sprintf("
Parsed user agents: %u
Total time elapsed: %s
Average time per user agent: %s
Detected Bots: %s (%s%%)
Detected device types:
%s
", $parsedUAs,
round($timeElapsed, 2),
round($timeElapsed / $parsedUAs, 6),
format($detectedBots, $parsedUAs),
getPercentage($detectedBots, $parsedUAs),
implode('', $reportStat)
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you do that in a new PR once that one was merged?
|
||
Asus: | ||
regex: 'FBMD/(?:K50IN|K54L|T100HAN|T103HAF|UX360CAK|X550LB|X553MA|X555LN|X556UQK);' | ||
device: 'desktop' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type notebook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to be notebook
in the original PR, but actually I think that wouldn't be good. We aren't able to say if it's a desktop or notebook in most cases. Having a new notebook type would look like we are able to detect that properly, but actually that only works for few cases...
replaces/based on #6292