diff options
author | Stefan Giehl <stefan@piwik.org> | 2018-06-07 01:29:46 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2018-06-07 01:29:46 +0300 |
commit | 5076bd6bfdc32b969f122a5ef65c02fb1ab3c5b2 (patch) | |
tree | b2785397e5506f8c305761025ddcd91aa2a6453c /plugins/DevicesDetection | |
parent | d8c98711edd6eebc16f1be3b87dac798d118b78c (diff) |
Use generic device model names if device type is known (#13015)
* Use generic device model names
* updates tests
* Update screenshots
Diffstat (limited to 'plugins/DevicesDetection')
5 files changed, 82 insertions, 26 deletions
diff --git a/plugins/DevicesDetection/Columns/DeviceModel.php b/plugins/DevicesDetection/Columns/DeviceModel.php index 932334e3ed..7fb1b9a015 100644 --- a/plugins/DevicesDetection/Columns/DeviceModel.php +++ b/plugins/DevicesDetection/Columns/DeviceModel.php @@ -8,6 +8,7 @@ */ namespace Piwik\Plugins\DevicesDetection\Columns; +use Piwik\Piwik; use Piwik\Tracker\Request; use Piwik\Tracker\Visitor; use Piwik\Tracker\Action; @@ -33,7 +34,23 @@ class DeviceModel extends Base $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); - return $parser->getModel(); + $model = $parser->getModel(); + + if (!empty($model)) { + return $model; + } + + $deviceType = $parser->getDeviceName(); + + if (!empty($deviceType)) { + return 'generic ' . $deviceType; + } + + if ($parser->isMobile()) { + return 'generic mobile'; + } + + return ''; } /** diff --git a/plugins/DevicesDetection/VisitorDetails.php b/plugins/DevicesDetection/VisitorDetails.php index 5b17fdc4e6..42c1410037 100644 --- a/plugins/DevicesDetection/VisitorDetails.php +++ b/plugins/DevicesDetection/VisitorDetails.php @@ -9,8 +9,8 @@ namespace Piwik\Plugins\DevicesDetection; +use Piwik\Piwik; use Piwik\Plugins\Live\VisitorDetailsAbstract; -use Piwik\View; require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php'; @@ -53,7 +53,7 @@ class VisitorDetails extends VisitorDetailsAbstract protected function getDeviceModel() { - return $this->details['config_device_model']; + return getModelName($this->details['config_device_model']); } protected function getOperatingSystemCode() @@ -130,7 +130,11 @@ class VisitorDetails extends VisitorDetailsAbstract $deviceTypeIcon = $visit->getColumn('deviceTypeIcon'); $deviceBrand = $visit->getColumn('deviceBrand'); $deviceModel = $visit->getColumn('deviceModel'); - $deviceName = trim($deviceBrand . " " . $deviceModel); + if ($deviceBrand == Piwik::translate('General_Unknown')) { + $deviceName = $deviceModel; + } else { + $deviceName = trim($deviceBrand . " " . $deviceModel); + } if (!isset($this->devices[$deviceType])) { $this->devices[$deviceType] = array( diff --git a/plugins/DevicesDetection/functions.php b/plugins/DevicesDetection/functions.php index 663e3361e9..deb384e921 100644 --- a/plugins/DevicesDetection/functions.php +++ b/plugins/DevicesDetection/functions.php @@ -172,13 +172,26 @@ function getModelName($label) $brand = null; $model = $label; } + if ($brand) { + $brand = getDeviceBrandLabel($brand); + if ($brand == Piwik::translate('General_Unknown')) { + $brand = null; + } + } if (!$model) { $model = Piwik::translate('General_Unknown'); + } else if (strpos($model, 'generic ') === 0) { + $model = substr($model, 8); + if ($model == 'mobile') { + $model = Piwik::translate('DevicesDetection_GenericDevice', Piwik::translate('DevicesDetection_MobileDevice')); + } else { + $model = Piwik::translate('DevicesDetection_GenericDevice', getDeviceTypeLabel($model)); + } } - if (!$brand) { + if (empty($brand)) { return $model; } - return getDeviceBrandLabel($brand) . ' - ' . $model; + return $brand . ' - ' . $model; } function getOSFamilyFullName($label) diff --git a/plugins/DevicesDetection/lang/en.json b/plugins/DevicesDetection/lang/en.json index c31c5726be..732deb200b 100644 --- a/plugins/DevicesDetection/lang/en.json +++ b/plugins/DevicesDetection/lang/en.json @@ -37,6 +37,8 @@ "Smartphone": "Smartphone", "PortableMediaPlayer": "Portable media player", "Devices": "Devices", + "GenericDevice": "Generic %s", + "MobileDevice": "Mobile device", "Tablet": "Tablet", "Phablet": "Phablet", "TV": "Tv", diff --git a/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getModel_day.xml b/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getModel_day.xml index da6473c98b..b05ae70087 100644 --- a/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getModel_day.xml +++ b/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getModel_day.xml @@ -1,26 +1,6 @@ <?xml version="1.0" encoding="utf-8" ?> <result> <row> - <label>Unknown</label> - <nb_uniq_visitors>2</nb_uniq_visitors> - <nb_visits>3</nb_visits> - <nb_actions>3</nb_actions> - <nb_users>0</nb_users> - <max_actions>1</max_actions> - <sum_visit_length>1808</sum_visit_length> - <bounce_count>3</bounce_count> - <goals> - <row idgoal='1'> - <nb_conversions>3</nb_conversions> - <nb_visits_converted>2</nb_visits_converted> - <revenue>62.26</revenue> - </row> - </goals> - <nb_conversions>3</nb_conversions> - <revenue>62.26</revenue> - <segment>deviceBrand==Unknown;deviceModel==</segment> - </row> - <row> <label>Apple - iPad</label> <nb_uniq_visitors>1</nb_uniq_visitors> <nb_visits>2</nb_visits> @@ -61,6 +41,46 @@ <segment>deviceBrand==Apple;deviceModel==iPhone+5S</segment> </row> <row> + <label>Unknown</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>2</nb_visits> + <nb_actions>2</nb_actions> + <nb_users>0</nb_users> + <max_actions>1</max_actions> + <sum_visit_length>724</sum_visit_length> + <bounce_count>2</bounce_count> + <goals> + <row idgoal='1'> + <nb_conversions>2</nb_conversions> + <nb_visits_converted>1</nb_visits_converted> + <revenue>52.26</revenue> + </row> + </goals> + <nb_conversions>2</nb_conversions> + <revenue>52.26</revenue> + <segment>deviceBrand==Unknown;deviceModel==</segment> + </row> + <row> + <label>Generic Desktop</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_actions>1</nb_actions> + <nb_users>0</nb_users> + <max_actions>1</max_actions> + <sum_visit_length>1084</sum_visit_length> + <bounce_count>1</bounce_count> + <goals> + <row idgoal='1'> + <nb_conversions>1</nb_conversions> + <nb_visits_converted>1</nb_visits_converted> + <revenue>10</revenue> + </row> + </goals> + <nb_conversions>1</nb_conversions> + <revenue>10</revenue> + <segment>deviceBrand==Unknown;deviceModel==generic+desktop</segment> + </row> + <row> <label>HTC - Butterfly</label> <nb_uniq_visitors>1</nb_uniq_visitors> <nb_visits>1</nb_visits> |