2020-07-29 10:07:14 +02:00
|
|
|
<?php
|
|
|
|
|
2022-09-16 13:53:49 +02:00
|
|
|
declare(strict_types=1);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
|
|
|
/*
|
2021-08-16 09:56:19 +02:00
|
|
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
2020-07-29 10:07:14 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
namespace DanielSiepmann\Tracking\Domain\Extractors;
|
2022-09-16 13:53:49 +02:00
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
use DanielSiepmann\Tracking\Domain\Model\Pageview;
|
|
|
|
use DanielSiepmann\Tracking\Domain\Model\Recordview;
|
|
|
|
|
|
|
|
class OperatingSystem implements PageviewExtractor, RecordviewExtractor
|
2020-07-29 10:07:14 +02:00
|
|
|
{
|
2021-08-16 09:56:19 +02:00
|
|
|
public function extractTagFromPageview(Pageview $pageview): array
|
2020-07-29 10:07:14 +02:00
|
|
|
{
|
2021-08-16 09:56:19 +02:00
|
|
|
return [new Tag('os', $this->getOperatingSystem($pageview->getUserAgent()))];
|
|
|
|
}
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
public function extractTagFromRecordview(Recordview $recordview): array
|
|
|
|
{
|
|
|
|
return [new Tag('os', $this->getOperatingSystem($recordview->getUserAgent()))];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getOperatingSystem(string $userAgent): string
|
|
|
|
{
|
2020-07-29 10:07:14 +02:00
|
|
|
if (mb_stripos($userAgent, 'Android') !== false) {
|
|
|
|
return 'Android';
|
|
|
|
}
|
|
|
|
if (mb_stripos($userAgent, 'Windows') !== false) {
|
|
|
|
return 'Windows';
|
|
|
|
}
|
|
|
|
if (mb_stripos($userAgent, 'Linux') !== false) {
|
|
|
|
return 'Linux';
|
|
|
|
}
|
|
|
|
if (mb_stripos($userAgent, 'Macintosh') !== false) {
|
|
|
|
return 'Macintosh';
|
|
|
|
}
|
|
|
|
if (mb_stripos($userAgent, 'CrOS') !== false) {
|
|
|
|
return 'Google Chrome OS';
|
|
|
|
}
|
|
|
|
if (mb_stripos($userAgent, 'OpenBSD') !== false) {
|
|
|
|
return 'OpenBSD';
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
mb_stripos($userAgent, 'iPad') !== false
|
|
|
|
|| mb_stripos($userAgent, 'iphone') !== false
|
|
|
|
) {
|
|
|
|
return 'iOS';
|
|
|
|
}
|
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
return 'Unkown';
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
}
|