From 3d222f3b7335e33aaff59531d41e240e462bbaf6 Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Thu, 30 May 2013 16:59:23 +1200
Subject: [PATCH] fixes #3961 Adding new segment deviceType

---
 plugins/DevicesDetection/API.php              |   4 +-
 plugins/DevicesDetection/DevicesDetection.php | 167 +++++++++++-------
 .../UserAgentParserEnhanced.php               |   2 +-
 plugins/DevicesDetection/functions.php        |   2 +-
 plugins/Live/Visitor.php                      |   9 +
 ...PITest__Live.getLastVisitsDetails_year.xml |  10 ++
 ...eTest__Live.getLastVisitsDetails_month.xml |  10 ++
 ...Support__Live.getLastVisitsDetails_day.xml |   2 +
 ...ecified__Live.getLastVisitsDetails_day.xml |   2 +
 ...eDays__Live.getLastVisitsDetails_month.xml |   3 +
 ...eportMetadata__API.getSegmentsMetadata.xml |   7 +
 ...Ordered__Live.getLastVisitsDetails_day.xml |   2 +
 ...thItems__Live.getLastVisitsDetails_day.xml |   3 +
 ...alAPI__Live.getLastVisitsDetails_range.xml |   3 +
 14 files changed, 156 insertions(+), 70 deletions(-)

diff --git a/plugins/DevicesDetection/API.php b/plugins/DevicesDetection/API.php
index 32dca0760b..c6572f28ad 100644
--- a/plugins/DevicesDetection/API.php
+++ b/plugins/DevicesDetection/API.php
@@ -9,9 +9,6 @@
  * @category Piwik_Plugins
  * @package Piwik_DevicesDetection
  */
-require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php';
-require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php';
-
 class Piwik_DevicesDetection_API
 {
 
@@ -60,6 +57,7 @@ class Piwik_DevicesDetection_API
     {
         $dataTable = $this->getDataTable('DevicesDetection_types', $idSite, $period, $date, $segment);
         $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getDeviceTypeLabel'));
+        $dataTable->filter('ColumnCallbackReplace', array('label', 'ucfirst'));
         $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getDeviceTypeLogo'));
         return $dataTable;
     }
diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php
index d18f768b21..2f97c48203 100644
--- a/plugins/DevicesDetection/DevicesDetection.php
+++ b/plugins/DevicesDetection/DevicesDetection.php
@@ -9,7 +9,8 @@
  * @category Piwik_Plugins
  * @package Piwik_DevicesDetection
  */
-require_once "UserAgentParserEnhanced/UserAgentParserEnhanced.php";
+require_once PIWIK_INCLUDE_PATH . "/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php";
+require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php';
 
 class Piwik_DevicesDetection extends Piwik_Plugin
 {
@@ -32,70 +33,78 @@ class Piwik_DevicesDetection extends Piwik_Plugin
 
     /*
      * Defines API reports.
-     * Also used to define Widgets.
+     * Also used to define Widgets, and Segment(s)
+     *
+     * @return array Category, Report Name, API Module, API action, Translated column name, & optional segment info
      *
-     * @array Category, Report Name, API Module, API action, Translated column name,
-     * W
      */
-
-    protected $reportMetadata = array(
-        // device types report
-        array(
-            'DevicesDetection_DevicesDetection',
-            'DevicesDetection_DeviceType',
-            'DevicesDetection',
-            'getType',
-            'DevicesDetection_DeviceType',
-        ),
-        // device brands report
-        array(
-            'DevicesDetection_DevicesDetection',
-            'DevicesDetection_DeviceBrand',
-            'DevicesDetection',
-            'getBrand',
-            'DevicesDetection_DeviceBrand',
-        ),
-        // device model report
-        array(
-            'DevicesDetection_DevicesDetection',
-            'DevicesDetection_DeviceModel',
-            'DevicesDetection',
-            'getModel',
-            'DevicesDetection_DeviceModel',
-        ),
-        // device OS family report
-        array(
-            'DevicesDetection_DevicesDetection',
-            'DeviceDetection_OperatingSystemFamilies',
-            'DevicesDetection',
-            'getOsFamilies',
-            'DeviceDetection_OperatingSystemFamilies',
-        ),
-        // device OS version report
-        array(
-            'DevicesDetection_DevicesDetection',
-            'DeviceDetection_OperatingSystemVersions',
-            'DevicesDetection',
-            'getOsVersions',
-            'DeviceDetection_OperatingSystemVersions',
-        ),
-        // Browser family report
-        array(
-            'DevicesDetection_DevicesDetection',
-            'DevicesDetection_BrowsersFamily',
-            'DevicesDetection',
-            'getBrowserFamilies',
-            'DevicesDetection_BrowsersFamily',
-        ),
-        // Browser versions report
-        array(
-            'DevicesDetection_DevicesDetection',
-            'DevicesDetection_BrowserVersions',
-            'DevicesDetection',
-            'getBrowserVersions',
-            'DevicesDetection_BrowserVersions',
-        ),
-    );
+    protected function getRawMetadataReports()
+    {
+        $report = array(
+            array(
+                'DevicesDetection_DevicesDetection',
+                'DevicesDetection_DeviceType',
+                'DevicesDetection',
+                'getType',
+                'DevicesDetection_DeviceType',
+
+                // Segment
+                'deviceType',
+                'log_visit.config_device_type',
+                implode(", ", UserAgentParserEnhanced::$deviceTypes), // comma separated examples
+                create_function('$type', 'return array_search( strtolower(trim(urldecode($type))), UserAgentParserEnhanced::$deviceTypes);')
+            ),
+            // device brands report
+            array(
+                'DevicesDetection_DevicesDetection',
+                'DevicesDetection_DeviceBrand',
+                'DevicesDetection',
+                'getBrand',
+                'DevicesDetection_DeviceBrand',
+            ),
+            // device model report
+            array(
+                'DevicesDetection_DevicesDetection',
+                'DevicesDetection_DeviceModel',
+                'DevicesDetection',
+                'getModel',
+                'DevicesDetection_DeviceModel',
+            ),
+            // device OS family report
+            array(
+                'DevicesDetection_DevicesDetection',
+                'DeviceDetection_OperatingSystemFamilies',
+                'DevicesDetection',
+                'getOsFamilies',
+                'DeviceDetection_OperatingSystemFamilies',
+            ),
+            // device OS version report
+            array(
+                'DevicesDetection_DevicesDetection',
+                'DeviceDetection_OperatingSystemVersions',
+                'DevicesDetection',
+                'getOsVersions',
+                'DeviceDetection_OperatingSystemVersions',
+            ),
+            // Browser family report
+            array(
+                'DevicesDetection_DevicesDetection',
+                'DevicesDetection_BrowsersFamily',
+                'DevicesDetection',
+                'getBrowserFamilies',
+                'DevicesDetection_BrowsersFamily',
+            ),
+            // Browser versions report
+            array(
+                'DevicesDetection_DevicesDetection',
+                'DevicesDetection_BrowserVersions',
+                'DevicesDetection',
+                'getBrowserVersions',
+                'DevicesDetection_BrowserVersions',
+            ),
+        );
+        return $report;
+    }
 
     public function getListHooksRegistered()
     {
@@ -106,12 +115,13 @@ class Piwik_DevicesDetection extends Piwik_Plugin
             'Tracker.newVisitorInformation' => 'parseMobileVisitData',
             'WidgetsList.add' => 'addWidgets',
             'API.getReportMetadata' => 'getReportMetadata',
+            'API.getSegmentsMetadata' => 'getSegmentsMetadata',
         );
     }
 
     public function addWidgets()
     {
-        foreach ($this->reportMetadata as $report) {
+        foreach ($this->getRawMetadataReports() as $report) {
             list($category, $name, $controllerName, $controllerAction) = $report;
             if ($category == false)
                 continue;
@@ -119,6 +129,33 @@ class Piwik_DevicesDetection extends Piwik_Plugin
         }
     }
 
+
+    /**
+     * Get segments meta data
+     *
+     * @param Piwik_Event_Notification $notification  notification object
+     */
+    public function getSegmentsMetadata($notification)
+    {
+        // Note: only one field segmented so far: deviceType
+        $segments =& $notification->getNotificationObject();
+        foreach ($this->getRawMetadataReports() as $report) {
+            @list($category, $name, $apiModule, $apiAction, $columnName, $segment, $sqlSegment, $acceptedValues) = $report;
+
+            if (empty($segment)) continue;
+            $segments[] = array(
+                'type'           => 'dimension',
+                'category'       => Piwik_Translate('General_Visit'),
+                'name'           => $columnName,
+                'segment'        => $segment,
+                'acceptedValues' => $acceptedValues,
+                'sqlSegment'     => $sqlSegment,
+                'sqlFilter'      => isset($sqlFilter) ? $sqlFilter : false,
+            );
+        }
+    }
+
+
     /**
      * @param Piwik_Event_Notification $notification  notification object
      */
@@ -127,7 +164,7 @@ class Piwik_DevicesDetection extends Piwik_Plugin
         $reports = & $notification->getNotificationObject();
 
         $i = 0;
-        foreach ($this->reportMetadata as $report) {
+        foreach ($this->getRawMetadataReports() as $report) {
             list($category, $name, $apiModule, $apiAction, $columnName) = $report;
             if ($category == false)
                 continue;
diff --git a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php
index 300b02d04c..d67c26f755 100644
--- a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php
+++ b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php
@@ -14,8 +14,8 @@ require_once('spyc.php');
 
 class UserAgentParserEnhanced
 {
+    public static $deviceTypes = array( 'desktop', 'smartphone', 'tablet', 'feature phone', 'console', 'tv', 'car browser' );
 
-    public static $deviceTypes = array('car browser', 'console', 'desktop', 'feature phone', 'smartphone', 'tablet', 'tv');
     public static $deviceBrands = array(
         'AC' => 'Acer',
         'AI' => 'Airness',
diff --git a/plugins/DevicesDetection/functions.php b/plugins/DevicesDetection/functions.php
index 7bf70a98c6..4819cd6974 100644
--- a/plugins/DevicesDetection/functions.php
+++ b/plugins/DevicesDetection/functions.php
@@ -72,7 +72,7 @@ function Piwik_getDeviceBrandLabel($label)
 function Piwik_getDeviceTypeLabel($label)
 {
     if (isset(UserAgentParserEnhanced::$deviceTypes[$label])) {
-        return ucfirst(UserAgentParserEnhanced::$deviceTypes[$label]);
+        return UserAgentParserEnhanced::$deviceTypes[$label];
     } else {
         return Piwik_Translate('General_Unknown');
     }
diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php
index fe839a67d8..8a8c984021 100644
--- a/plugins/Live/Visitor.php
+++ b/plugins/Live/Visitor.php
@@ -107,6 +107,7 @@ class Piwik_Live_Visitor
             'browserCode'                 => $this->getBrowserCode(),
             'browserVersion'              => $this->getBrowserVersion(),
             'screenType'                  => $this->getScreenType(),
+            'deviceType'                  => $this->getDeviceType(),
             'resolution'                  => $this->getResolution(),
             'screenTypeIcon'              => $this->getScreenTypeIcon(),
             'plugins'                     => $this->getPlugins(),
@@ -507,6 +508,14 @@ class Piwik_Live_Visitor
         return Piwik_getScreenTypeFromResolution($this->details['config_resolution']);
     }
 
+    function getDeviceType()
+    {
+        if(Piwik_PluginsManager::getInstance()->isPluginActivated('DevicesDetection')) {
+            return Piwik_getDeviceTypeLabel($this->details['config_device_type']);
+        }
+        return false;
+    }
+
     function getResolution()
     {
         return $this->details['config_resolution'];
diff --git a/tests/PHPUnit/Integration/expected/test_AutoSuggestAPITest__Live.getLastVisitsDetails_year.xml b/tests/PHPUnit/Integration/expected/test_AutoSuggestAPITest__Live.getLastVisitsDetails_year.xml
index a2317c4dd9..dad9681c06 100644
--- a/tests/PHPUnit/Integration/expected/test_AutoSuggestAPITest__Live.getLastVisitsDetails_year.xml
+++ b/tests/PHPUnit/Integration/expected/test_AutoSuggestAPITest__Live.getLastVisitsDetails_year.xml
@@ -85,6 +85,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -224,6 +225,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -346,6 +348,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -468,6 +471,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -590,6 +594,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -729,6 +734,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -851,6 +857,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -973,6 +980,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -1095,6 +1103,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -1234,6 +1243,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
diff --git a/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml b/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml
index a2317c4dd9..dad9681c06 100644
--- a/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml
+++ b/tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__Live.getLastVisitsDetails_month.xml
@@ -85,6 +85,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -224,6 +225,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -346,6 +348,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -468,6 +471,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -590,6 +594,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -729,6 +734,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -851,6 +857,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -973,6 +980,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -1095,6 +1103,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -1234,6 +1243,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
diff --git a/tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_withCookieSupport__Live.getLastVisitsDetails_day.xml b/tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_withCookieSupport__Live.getLastVisitsDetails_day.xml
index 13c0a290aa..d458df0826 100644
--- a/tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_withCookieSupport__Live.getLastVisitsDetails_day.xml
+++ b/tests/PHPUnit/Integration/expected/test_OneVisitorTwoVisits_withCookieSupport__Live.getLastVisitsDetails_day.xml
@@ -86,6 +86,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -271,6 +272,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
diff --git a/tests/PHPUnit/Integration/expected/test_OneVisitor_NoKeywordSpecified__Live.getLastVisitsDetails_day.xml b/tests/PHPUnit/Integration/expected/test_OneVisitor_NoKeywordSpecified__Live.getLastVisitsDetails_day.xml
index 793a396614..61cbbe181f 100644
--- a/tests/PHPUnit/Integration/expected/test_OneVisitor_NoKeywordSpecified__Live.getLastVisitsDetails_day.xml
+++ b/tests/PHPUnit/Integration/expected/test_OneVisitor_NoKeywordSpecified__Live.getLastVisitsDetails_day.xml
@@ -75,6 +75,7 @@
 		<browserCode>UNK</browserCode>
 		<browserVersion>UNK</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>Inconnu</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -179,6 +180,7 @@
 		<browserCode>UNK</browserCode>
 		<browserVersion>UNK</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>Inconnu</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
diff --git a/tests/PHPUnit/Integration/expected/test_OneVisitor_SeveralDays_ImportedInRandomOrderTest_shouldShowOneVisit_InEachOfThreeDays__Live.getLastVisitsDetails_month.xml b/tests/PHPUnit/Integration/expected/test_OneVisitor_SeveralDays_ImportedInRandomOrderTest_shouldShowOneVisit_InEachOfThreeDays__Live.getLastVisitsDetails_month.xml
index 09d0f98a41..ff47120092 100644
--- a/tests/PHPUnit/Integration/expected/test_OneVisitor_SeveralDays_ImportedInRandomOrderTest_shouldShowOneVisit_InEachOfThreeDays__Live.getLastVisitsDetails_month.xml
+++ b/tests/PHPUnit/Integration/expected/test_OneVisitor_SeveralDays_ImportedInRandomOrderTest_shouldShowOneVisit_InEachOfThreeDays__Live.getLastVisitsDetails_month.xml
@@ -74,6 +74,7 @@
 		<browserCode>IE</browserCode>
 		<browserVersion>7.0</browserVersion>
 		<screenType>unknown</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>unknown</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/unknown.gif</screenTypeIcon>
 		<plugins />
@@ -158,6 +159,7 @@
 		<browserCode>IE</browserCode>
 		<browserVersion>7.0</browserVersion>
 		<screenType>unknown</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>unknown</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/unknown.gif</screenTypeIcon>
 		<plugins />
@@ -242,6 +244,7 @@
 		<browserCode>IE</browserCode>
 		<browserVersion>7.0</browserVersion>
 		<screenType>unknown</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>unknown</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/unknown.gif</screenTypeIcon>
 		<plugins />
diff --git a/tests/PHPUnit/Integration/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml b/tests/PHPUnit/Integration/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml
index d87aac161f..61062e2f50 100644
--- a/tests/PHPUnit/Integration/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml
+++ b/tests/PHPUnit/Integration/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml
@@ -106,6 +106,13 @@
 		<segment>browserVersion</segment>
 		<acceptedValues>1.0, 8.0, etc.</acceptedValues>
 	</row>
+	<row>
+		<type>dimension</type>
+		<category>Visit</category>
+		<name>Device type</name>
+		<segment>deviceType</segment>
+		<acceptedValues>desktop, smartphone, tablet, feature phone, console, tv, car browser</acceptedValues>
+	</row>
 	<row>
 		<type>dimension</type>
 		<category>Visit</category>
diff --git a/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_LiveEcommerceStatusOrdered__Live.getLastVisitsDetails_day.xml b/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_LiveEcommerceStatusOrdered__Live.getLastVisitsDetails_day.xml
index d18aa5cc33..1e70eaad82 100644
--- a/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_LiveEcommerceStatusOrdered__Live.getLastVisitsDetails_day.xml
+++ b/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_LiveEcommerceStatusOrdered__Live.getLastVisitsDetails_day.xml
@@ -113,6 +113,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -321,6 +322,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
diff --git a/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems__Live.getLastVisitsDetails_day.xml b/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems__Live.getLastVisitsDetails_day.xml
index 0c7af9ad9a..3a8136645a 100644
--- a/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems__Live.getLastVisitsDetails_day.xml
+++ b/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems__Live.getLastVisitsDetails_day.xml
@@ -189,6 +189,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -516,6 +517,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -725,6 +727,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>normal</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1024x768</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/normal.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
diff --git a/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getLastVisitsDetails_range.xml b/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getLastVisitsDetails_range.xml
index 8f93ea84c7..03c04a6a69 100644
--- a/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getLastVisitsDetails_range.xml
+++ b/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getLastVisitsDetails_range.xml
@@ -83,6 +83,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.0</browserVersion>
 		<screenType>dual</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1111x222</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/dual.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -195,6 +196,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.0</browserVersion>
 		<screenType>dual</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1111x222</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/dual.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
@@ -367,6 +369,7 @@
 		<browserCode>FF</browserCode>
 		<browserVersion>3.6</browserVersion>
 		<screenType>dual</screenType>
+		<deviceType>desktop</deviceType>
 		<resolution>1111x222</resolution>
 		<screenTypeIcon>plugins/UserSettings/images/screens/dual.gif</screenTypeIcon>
 		<plugins>flash, java</plugins>
-- 
GitLab