Skip to content

Commit

Permalink
use DeviceDetector instead of old UserAgentParser
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Apr 3, 2014
1 parent cde0263 commit 7a98bec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions core/Tracker/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Piwik\IP;
use Piwik\Piwik;
use Piwik\Tracker;
use UserAgentParser;
use DeviceDetector;

/**
* Class used to handle a Visit.
Expand Down Expand Up @@ -592,20 +592,22 @@ protected function getUserSettingsInformation()
if (is_array($this->userSettingsInformation)) {
return $this->userSettingsInformation;
}
require_once PIWIK_INCLUDE_PATH . '/libs/UserAgentParser/UserAgentParser.php';

list($plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF,
$plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie) = $this->request->getPlugins();

$resolution = $this->request->getParam('res');
$userAgent = $this->request->getUserAgent();
$aBrowserInfo = UserAgentParser::getBrowser($userAgent);

$browserName = ($aBrowserInfo !== false && $aBrowserInfo['id'] !== false) ? $aBrowserInfo['id'] : 'UNK';
$deviceDetector = new DeviceDetector($userAgent);
$deviceDetector->parse();
$aBrowserInfo = $deviceDetector->getBrowser();

$browserName = ($aBrowserInfo !== false && $aBrowserInfo['short_name'] !== false) ? $aBrowserInfo['short_name'] : 'UNK';
$browserVersion = ($aBrowserInfo !== false && $aBrowserInfo['version'] !== false) ? $aBrowserInfo['version'] : '';

$os = UserAgentParser::getOperatingSystem($userAgent);
$os = $os === false ? 'UNK' : $os['id'];
$os = $deviceDetector->getOS();
$os = empty($os['short_name']) ? 'UNK' : $os['short_name'];

$browserLang = substr($this->request->getBrowserLanguage(), 0, 20); // limit the length of this string to match db
$configurationHash = $this->getConfigHash(
Expand Down
2 changes: 1 addition & 1 deletion plugins/UserSettings/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getOS($idSite, $period, $date, $segment = false, $addShortLabel

/**
* Gets a DataTable displaying number of visits by operating system family. The operating
* system families are listed in /libs/UserAgentParser/UserAgentParser.php.
* system families are listed in vendor piwik/device-detector.
*/
public function getOSFamily($idSite, $period, $date, $segment = false)
{
Expand Down

0 comments on commit 7a98bec

Please sign in to comment.