diff options
author | Stefan Giehl <stefan@piwik.org> | 2018-01-07 02:41:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-07 02:41:29 +0300 |
commit | 390edc755a4ae1f5e88542189a8e19d5c5155dfd (patch) | |
tree | 9c36de1402bcb89207c5fbcacc9972deb4fce78b | |
parent | 48864a124789b665a649e6e5bd75692048fcba76 (diff) |
Adds segment for device model (#12298)
* Adds segment for device model
and segmented visitor log link to device model report
* update tests
* submodule update
10 files changed, 61 insertions, 0 deletions
diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions -Subproject 0106441a5d4873aaacc08d2143551669d956348 +Subproject 097b3454fdf99554a5ba1bca102c0a2de728e90 diff --git a/plugins/DevicesDetection/API.php b/plugins/DevicesDetection/API.php index 3cd5c13e80..667affa57b 100644 --- a/plugins/DevicesDetection/API.php +++ b/plugins/DevicesDetection/API.php @@ -111,6 +111,26 @@ class API extends \Piwik\Plugin\API public function getModel($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_models', $idSite, $period, $date, $segment); + + $dataTable->filter(function (DataTable $table) { + foreach ($table->getRowsWithoutSummaryRow() as $row) { + + $label = $row->getColumn('label'); + + if (strpos($label, ';') !== false) { + list($brand, $model) = explode(';', $label, 2); + $brand = getDeviceBrandLabel($brand); + } else { + $brand = null; + $model = $label; + } + + $segment = sprintf('deviceBrand==%s;deviceModel==%s', urlencode($brand), urlencode($model)); + + $row->setMetadata('segment', $segment); + } + }); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getModelName')); return $dataTable; } diff --git a/plugins/DevicesDetection/Columns/DeviceModel.php b/plugins/DevicesDetection/Columns/DeviceModel.php index 4ac962f0e1..932334e3ed 100644 --- a/plugins/DevicesDetection/Columns/DeviceModel.php +++ b/plugins/DevicesDetection/Columns/DeviceModel.php @@ -19,6 +19,8 @@ class DeviceModel extends Base protected $type = self::TYPE_TEXT; protected $nameSingular = 'DevicesDetection_DeviceModel'; protected $namePlural = 'DevicesDetection_DeviceModels'; + protected $segmentName = 'deviceModel'; + protected $acceptValues = 'iPad, Nexus 5, Galaxy S5, Fire TV, etc.'; /** * @param Request $request 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 3ed4a7857a..da6473c98b 100644 --- a/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getModel_day.xml +++ b/plugins/DevicesDetection/tests/System/expected/test___DevicesDetection.getModel_day.xml @@ -18,6 +18,7 @@ </goals> <nb_conversions>3</nb_conversions> <revenue>62.26</revenue> + <segment>deviceBrand==Unknown;deviceModel==</segment> </row> <row> <label>Apple - iPad</label> @@ -37,6 +38,7 @@ </goals> <nb_conversions>1</nb_conversions> <revenue>42.26</revenue> + <segment>deviceBrand==Apple;deviceModel==iPad</segment> </row> <row> <label>Apple - iPhone 5S</label> @@ -56,6 +58,7 @@ </goals> <nb_conversions>1</nb_conversions> <revenue>10</revenue> + <segment>deviceBrand==Apple;deviceModel==iPhone+5S</segment> </row> <row> <label>HTC - Butterfly</label> @@ -75,6 +78,7 @@ </goals> <nb_conversions>1</nb_conversions> <revenue>42.26</revenue> + <segment>deviceBrand==HTC;deviceModel==Butterfly</segment> </row> <row> <label>Philips - Blu-ray Player (BDP5600)</label> @@ -86,6 +90,7 @@ <sum_visit_length>0</sum_visit_length> <bounce_count>1</bounce_count> <nb_visits_converted>0</nb_visits_converted> + <segment>deviceBrand==Philips;deviceModel==Blu-ray+Player+%28BDP5600%29</segment> </row> <row> <label>Samsung - GALAXY Tab 3 8.0" WiFi</label> @@ -97,6 +102,7 @@ <sum_visit_length>0</sum_visit_length> <bounce_count>1</bounce_count> <nb_visits_converted>0</nb_visits_converted> + <segment>deviceBrand==Samsung;deviceModel==GALAXY+Tab+3+8.0%22+WiFi</segment> </row> <row> <label>ViewSonic - ViewPad 7e</label> @@ -116,5 +122,6 @@ </goals> <nb_conversions>1</nb_conversions> <revenue>10</revenue> + <segment>deviceBrand==ViewSonic;deviceModel==ViewPad+7e</segment> </row> </result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_AutoSuggestAPITest_deviceModel__API.getSuggestedValuesForSegment.xml b/tests/PHPUnit/System/expected/test_AutoSuggestAPITest_deviceModel__API.getSuggestedValuesForSegment.xml new file mode 100644 index 0000000000..75cef6bae6 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_AutoSuggestAPITest_deviceModel__API.getSuggestedValuesForSegment.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row>GALAXY Note 3</row> + <row>Nexus 4</row> + <row>Desire</row> + <row>Xperia Tablet S</row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_AutoSuggestAPITest_deviceModel__VisitsSummary.get_range.xml b/tests/PHPUnit/System/expected/test_AutoSuggestAPITest_deviceModel__VisitsSummary.get_range.xml new file mode 100644 index 0000000000..0e04d3f6d9 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_AutoSuggestAPITest_deviceModel__VisitsSummary.get_range.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_visits>2</nb_visits> + <nb_actions>6</nb_actions> + <nb_visits_converted>2</nb_visits_converted> + <bounce_count>1</bounce_count> + <sum_visit_length>1621</sum_visit_length> + <max_actions>5</max_actions> + <bounce_rate>50%</bounce_rate> + <nb_actions_per_visit>3</nb_actions_per_visit> + <avg_time_on_site>811</avg_time_on_site> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__DevicesDetection.getModel_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__DevicesDetection.getModel_month.xml index 085d51d878..6dd1e6a37c 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__DevicesDetection.getModel_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__DevicesDetection.getModel_month.xml @@ -19,6 +19,7 @@ <sum_daily_nb_uniq_visitors>38</sum_daily_nb_uniq_visitors> <sum_daily_nb_users>2</sum_daily_nb_users> <nb_visits_converted>0</nb_visits_converted> + <segment>deviceBrand==Unknown;deviceModel==</segment> </row> <row> <label>HTC - Vision</label> @@ -38,6 +39,7 @@ <revenue>10</revenue> <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors> <sum_daily_nb_users>0</sum_daily_nb_users> + <segment>deviceBrand==HTC;deviceModel==Vision</segment> </row> <row> <label>Apple - iPhone</label> @@ -57,6 +59,7 @@ <revenue>5</revenue> <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors> <sum_daily_nb_users>0</sum_daily_nb_users> + <segment>deviceBrand==Apple;deviceModel==iPhone</segment> </row> <row> <label>Samsung - GALAXY S5</label> @@ -76,5 +79,6 @@ <revenue>5</revenue> <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors> <sum_daily_nb_users>1</sum_daily_nb_users> + <segment>deviceBrand==Samsung;deviceModel==GALAXY+S5</segment> </row> </result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__DevicesDetection.getModel_day.xml b/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__DevicesDetection.getModel_day.xml index faf5f2c061..3cb56dd1d6 100644 --- a/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__DevicesDetection.getModel_day.xml +++ b/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits__DevicesDetection.getModel_day.xml @@ -22,5 +22,6 @@ </goals> <nb_conversions>2</nb_conversions> <revenue>43</revenue> + <segment>deviceBrand==Unknown;deviceModel==</segment> </row> </result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits_withCookieSupport__DevicesDetection.getModel_day.xml b/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits_withCookieSupport__DevicesDetection.getModel_day.xml index da61c550e1..e8d76d31f4 100644 --- a/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits_withCookieSupport__DevicesDetection.getModel_day.xml +++ b/tests/PHPUnit/System/expected/test_OneVisitorTwoVisits_withCookieSupport__DevicesDetection.getModel_day.xml @@ -23,5 +23,6 @@ </goals> <nb_conversions>2</nb_conversions> <revenue>43</revenue> + <segment>deviceBrand==Unknown;deviceModel==</segment> </row> </result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml b/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml index 240f8fa562..0f31a40f7b 100644 --- a/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml +++ b/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getSegmentsMetadata.xml @@ -104,6 +104,13 @@ <row> <type>dimension</type> <category>Visitors</category> + <name>Device model</name> + <segment>deviceModel</segment> + <acceptedValues>iPad, Nexus 5, Galaxy S5, Fire TV, etc.</acceptedValues> + </row> + <row> + <type>dimension</type> + <category>Visitors</category> <name>Device type</name> <segment>deviceType</segment> <acceptedValues>desktop, smartphone, tablet, feature phone, console, tv, car browser, smart display, camera, portable media player, phablet</acceptedValues> |