diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-12-04 04:51:01 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-12-04 04:51:01 +0300 |
commit | 55038d27f089c07eb28435f263b0e74be5285ff3 (patch) | |
tree | 2c2f0b6f0c11127e6906a3c7006dfaff8fdc0335 /plugins | |
parent | 9f489412ef05e60f327c4f1945be94c99fdc5a8c (diff) | |
parent | dc55de6d759bd436f3d920b164435b1c7796cdbf (diff) |
Merge pull request #9314 from piwik/action_type_segment
New segment: ActionType
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Actions/ArchivingHelper.php | 2 | ||||
-rw-r--r-- | plugins/Actions/Columns/ActionType.php | 70 | ||||
-rw-r--r-- | plugins/Actions/lang/en.json | 3 | ||||
-rw-r--r-- | plugins/Events/Actions/ActionEvent.php | 14 | ||||
-rw-r--r-- | plugins/Live/Visitor.php | 8 | ||||
-rw-r--r-- | plugins/SegmentEditor/SegmentSelectorControl.php | 13 |
6 files changed, 90 insertions, 20 deletions
diff --git a/plugins/Actions/ArchivingHelper.php b/plugins/Actions/ArchivingHelper.php index b5735225b8..192a3089ba 100644 --- a/plugins/Actions/ArchivingHelper.php +++ b/plugins/Actions/ArchivingHelper.php @@ -53,7 +53,7 @@ class ArchivingHelper unset($row[PiwikMetrics::INDEX_SITE_SEARCH_HAS_NO_RESULT]); } - if ($row['type'] == Action::TYPE_CONTENT) { + if (in_array($row['type'], array(Action::TYPE_CONTENT, Action::TYPE_EVENT))) { continue; } diff --git a/plugins/Actions/Columns/ActionType.php b/plugins/Actions/Columns/ActionType.php new file mode 100644 index 0000000000..3d6e9b599a --- /dev/null +++ b/plugins/Actions/Columns/ActionType.php @@ -0,0 +1,70 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\Actions\Columns; + +use Piwik\Piwik; +use Piwik\Plugin\Dimension\ActionDimension; +use Piwik\Plugins\Actions\Segment; +use Piwik\Tracker\Action; +use Exception; + +/** + * This example dimension only defines a name and does not track any data. It's supposed to be only used in reports. + * + * See {@link http://developer.piwik.org/api-reference/Piwik/Columns\Dimension} for more information. + */ +class ActionType extends ActionDimension +{ + private $types = array( + Action::TYPE_PAGE_URL => 'pageviews', + Action::TYPE_CONTENT => 'contents', + Action::TYPE_SITE_SEARCH => 'sitesearches', + Action::TYPE_EVENT => 'events', + Action::TYPE_OUTLINK => 'outlinks', + Action::TYPE_DOWNLOAD => 'downloads' + ); + + /** + * The name of the dimension which will be visible for instance in the UI of a related report and in the mobile app. + * @return string + */ + public function getName() + { + return Piwik::translate('Actions_ActionType'); + } + + protected function configureSegments() + { + $types = $this->types; + + $segment = new Segment(); + $segment->setSegment('actionType'); + $segment->setName('Actions_ActionType'); + $segment->setSqlSegment('log_action.type'); + $segment->setType(Segment::TYPE_METRIC); + $segment->setAcceptedValues(sprintf('A type of action, such as: %s', implode(', ', $types))); + $segment->setSqlFilter(function ($type) use ($types) { + if (array_key_exists($type, $types)) { + return $type; + } + + $index = array_search(strtolower(trim(urldecode($type))), $types); + + if ($index === false) { + throw new Exception("actionType must be one of: " . implode(', ', $types)); + } + + return $index; + }); + $segment->setSuggestedValuesCallback(function ($idSite, $maxSuggestionsToReturn) use ($types) { + return array_slice(array_values($types), 0, $maxSuggestionsToReturn); + }); + $this->addSegment($segment); + } +}
\ No newline at end of file diff --git a/plugins/Actions/lang/en.json b/plugins/Actions/lang/en.json index b4853e18f5..f176db870d 100644 --- a/plugins/Actions/lang/en.json +++ b/plugins/Actions/lang/en.json @@ -61,6 +61,7 @@ "WidgetPageUrlsFollowingSearch": "Pages Following a Site Search", "WidgetSearchCategories": "Search Categories", "WidgetSearchKeywords": "Site Search Keywords", - "WidgetSearchNoResultKeywords": "Search Keywords with No Results" + "WidgetSearchNoResultKeywords": "Search Keywords with No Results", + "ActionType": "Action Type" } }
\ No newline at end of file diff --git a/plugins/Events/Actions/ActionEvent.php b/plugins/Events/Actions/ActionEvent.php index 9921c8d39b..5106ec6092 100644 --- a/plugins/Events/Actions/ActionEvent.php +++ b/plugins/Events/Actions/ActionEvent.php @@ -60,9 +60,17 @@ class ActionEvent extends Action protected function getActionsToLookup() { - return array( - 'idaction_url' => $this->getUrlAndType() - ); + $actionUrl = false; + + $url = $this->getActionUrl(); + + if (!empty($url)) { + // normalize urls by stripping protocol and www + $url = Tracker\PageUrl::normalizeUrl($url); + $actionUrl = array($url['url'], $this->getActionType(), $url['prefixId']); + } + + return array('idaction_url' => $actionUrl); } // Do not track this Event URL as Entry/Exit Page URL (leave the existing entry/exit) diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php index 6d679a8a05..fa7be4dd63 100644 --- a/plugins/Live/Visitor.php +++ b/plugins/Live/Visitor.php @@ -286,7 +286,7 @@ class Visitor implements VisitorInterface unset($actionDetails[$actionIdx]); continue; - } elseif ($actionDetail['type'] == Action::TYPE_EVENT_CATEGORY) { + } elseif ($actionDetail['type'] == Action::TYPE_EVENT) { // Handle Event if (strlen($actionDetail['pageTitle']) > 0) { $actionDetail['eventName'] = $actionDetail['pageTitle']; @@ -301,7 +301,7 @@ class Visitor implements VisitorInterface } // Event value / Generation time - if ($actionDetail['type'] == Action::TYPE_EVENT_CATEGORY) { + if ($actionDetail['type'] == Action::TYPE_EVENT) { if (strlen($actionDetail['custom_float']) > 0) { $actionDetail['eventValue'] = round($actionDetail['custom_float'], self::EVENT_VALUE_PRECISION); } @@ -310,7 +310,7 @@ class Visitor implements VisitorInterface } unset($actionDetail['custom_float']); - if ($actionDetail['type'] != Action::TYPE_EVENT_CATEGORY) { + if ($actionDetail['type'] != Action::TYPE_EVENT) { unset($actionDetail['eventCategory']); unset($actionDetail['eventAction']); } @@ -423,7 +423,7 @@ class Visitor implements VisitorInterface $details['type'] = 'search'; $details['icon'] = 'plugins/Morpheus/images/search_ico.png'; break; - case Action::TYPE_EVENT_CATEGORY: + case Action::TYPE_EVENT: $details['type'] = 'event'; $details['icon'] = 'plugins/Morpheus/images/event.png'; break; diff --git a/plugins/SegmentEditor/SegmentSelectorControl.php b/plugins/SegmentEditor/SegmentSelectorControl.php index b01018dbcf..72be071e5e 100644 --- a/plugins/SegmentEditor/SegmentSelectorControl.php +++ b/plugins/SegmentEditor/SegmentSelectorControl.php @@ -46,9 +46,10 @@ class SegmentSelectorControl extends UIControl $segments = APIMetadata::getInstance()->getSegmentsMetadata($this->idSite); + $visitTitle = Piwik::translate('General_Visit'); $segmentsByCategory = array(); foreach ($segments as $segment) { - if ($segment['category'] == Piwik::translate('General_Visit') + if ($segment['category'] == $visitTitle && ($segment['type'] == 'metric' && $segment['segment'] != 'visitIp') ) { $metricsLabel = Piwik::translate('General_Metrics'); @@ -57,7 +58,6 @@ class SegmentSelectorControl extends UIControl } $segmentsByCategory[$segment['category']][] = $segment; } - uksort($segmentsByCategory, array($this, 'sortSegmentCategories')); $this->createRealTimeSegmentsIsEnabled = Config::getInstance()->General['enable_create_realtime_segments']; $this->segmentsByCategory = $segmentsByCategory; @@ -100,15 +100,6 @@ class SegmentSelectorControl extends UIControl return (bool) $savedSegment['auto_archive']; } - public function sortSegmentCategories($a, $b) - { - // Custom Variables last - if ($a == Piwik::translate('CustomVariables_CustomVariables')) { - return 1; - } - return 0; - } - private function getTranslations() { $translationKeys = array( |