blob: 5c8369f46a9dc148c067a077bb296e04657d0144 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\DevicesDetection\Columns;
use Piwik\Piwik;
use Piwik\Plugin\Segment;
use Piwik\Tracker\Request;
use DeviceDetector;
use Exception;
class DeviceType extends Base
{
protected $fieldName = 'config_device_type';
protected $fieldType = 'TINYINT( 100 ) NULL DEFAULT NULL';
protected function init()
{
$deviceTypeList = implode(", ", DeviceDetector::$deviceTypes);
$segment = new Segment();
$segment->setSegment('deviceType');
$segment->setName('DevicesDetection_DeviceType');
$segment->setAcceptValues($deviceTypeList);
$segment->setSqlFilter(function ($type) use ($deviceTypeList) {
$index = array_search(strtolower(trim(urldecode($type))), DeviceDetector::$deviceTypes);
if ($index === false) {
throw new Exception("deviceType segment must be one of: $deviceTypeList");
}
return $index;
});
$this->addSegment($segment);
}
public function getName()
{
return Piwik::translate('DevicesDetection_DeviceType');
}
public function onNewVisit(Request $request, $visit)
{
$userAgent = $request->getUserAgent();
$parser = $this->getUAParser($userAgent);
return $parser->getDevice();
}
}
|