diff options
author | Stefan Giehl <stefan@piwik.org> | 2017-09-15 00:54:01 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2017-09-15 00:54:01 +0300 |
commit | 40f886baf0e3ce5bbe4a066b333a7cc24eb93163 (patch) | |
tree | 93418e061ccf95d86383504d4c778b305aee8792 /plugins | |
parent | 595da1313efd43a0a60c1797364da42511d46de6 (diff) |
Makes visitor log/profile independent from Events plugin (#12047)
* makes profile query independent from events plugin
* move more stuff to event plugin
* update test files
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Actions/VisitorDetails.php | 59 | ||||
-rw-r--r-- | plugins/Events/Events.php | 1 | ||||
-rw-r--r-- | plugins/Events/VisitorDetails.php | 20 |
3 files changed, 43 insertions, 37 deletions
diff --git a/plugins/Actions/VisitorDetails.php b/plugins/Actions/VisitorDetails.php index 7292bd87f5..becb6cdaf7 100644 --- a/plugins/Actions/VisitorDetails.php +++ b/plugins/Actions/VisitorDetails.php @@ -22,8 +22,6 @@ use Piwik\View; class VisitorDetails extends VisitorDetailsAbstract { - const EVENT_VALUE_PRECISION = 3; - public function extendVisitorDetails(&$visitor) { $visitor['searches'] = $this->details['visit_total_searches']; @@ -50,19 +48,11 @@ class VisitorDetails extends VisitorDetailsAbstract $formatter = new Formatter(); - $actionTypesToHandle = array( - Action::TYPE_PAGE_URL, - Action::TYPE_SITE_SEARCH, - Action::TYPE_EVENT, - Action::TYPE_OUTLINK, - Action::TYPE_DOWNLOAD - ); - // Enrich with time spent per action $nextActionId = 0; foreach ($actionDetails as $idx => &$action) { - if ($idx < $nextActionId || !in_array($action['type'], $actionTypesToHandle)) { + if ($idx < $nextActionId || !$this->shouldHandleAction($action)) { continue; // skip to next action having timeSpentRef } @@ -71,7 +61,7 @@ class VisitorDetails extends VisitorDetailsAbstract $nextAction = null; while (isset($actionDetails[$nextActionId]) && - (!in_array($actionDetails[$nextActionId]['type'], $actionTypesToHandle) || + (!$this->shouldHandleAction($actionDetails[$nextActionId]) || !array_key_exists('timeSpentRef', $actionDetails[$nextActionId]))) { $nextActionId++; } @@ -107,40 +97,37 @@ class VisitorDetails extends VisitorDetailsAbstract $actions = $actionDetails; } + private function shouldHandleAction($action) { + $actionTypesToHandle = array( + Action::TYPE_PAGE_URL, + Action::TYPE_SITE_SEARCH, + Action::TYPE_EVENT, + Action::TYPE_OUTLINK, + Action::TYPE_DOWNLOAD + ); + + return in_array($action['type'], $actionTypesToHandle) || !empty($action['eventType']); + } + public function extendActionDetails(&$action, $nextAction, $visitorDetails) { $formatter = new Formatter(); - if ($action['type'] == Action::TYPE_EVENT) { - // Handle Event - if (strlen($action['pageTitle']) > 0) { - $action['eventName'] = $action['pageTitle']; - } - + if ($action['type'] == Action::TYPE_SITE_SEARCH) { + // Handle Site Search + $action['siteSearchKeyword'] = $action['pageTitle']; unset($action['pageTitle']); - - } else { - if ($action['type'] == Action::TYPE_SITE_SEARCH) { - // Handle Site Search - $action['siteSearchKeyword'] = $action['pageTitle']; - unset($action['pageTitle']); - } } - // Event value / Generation time - if ($action['type'] == Action::TYPE_EVENT) { - if (strlen($action['custom_float']) > 0) { - $action['eventValue'] = round($action['custom_float'], self::EVENT_VALUE_PRECISION); - } - } elseif (isset($action['custom_float']) && $action['custom_float'] > 0) { + // Generation time + if ($this->shouldHandleAction($action) && empty($action['eventType']) && isset($action['custom_float']) && $action['custom_float'] > 0) { $action['generationTimeMilliseconds'] = $action['custom_float']; $action['generationTime'] = $formatter->getPrettyTimeFromSeconds($action['custom_float'] / 1000, true); + unset($action['custom_float']); } - unset($action['custom_float']); - if ($action['type'] != Action::TYPE_EVENT) { - unset($action['eventCategory']); - unset($action['eventAction']); + if (array_key_exists('custom_float', $action) && is_null($action['custom_float'])) { + unset($action['custom_float']); } if (array_key_exists('interaction_position', $action)) { @@ -214,7 +201,7 @@ class VisitorDetails extends VisitorDetailsAbstract $sql = " SELECT log_link_visit_action.idvisit, - COALESCE(log_action_event_category.type, log_action.type, log_action_title.type) AS type, + COALESCE(log_action.type, log_action_title.type) AS type, log_action.name AS url, log_action.url_prefix, log_action_title.name AS pageTitle, diff --git a/plugins/Events/Events.php b/plugins/Events/Events.php index eee4ce7f52..d3fc8501f1 100644 --- a/plugins/Events/Events.php +++ b/plugins/Events/Events.php @@ -263,6 +263,7 @@ class Events extends \Piwik\Plugin public function provideActionDimensionFields(&$fields, &$joins) { + $fields[] = 'log_action_event_category.type AS eventType'; $fields[] = 'log_action_event_category.name AS eventCategory'; $fields[] = 'log_action_event_action.name as eventAction'; $joins[] = 'LEFT JOIN ' . Common::prefixTable('log_action') . ' AS log_action_event_action diff --git a/plugins/Events/VisitorDetails.php b/plugins/Events/VisitorDetails.php index 76dfd37806..ecf76847d8 100644 --- a/plugins/Events/VisitorDetails.php +++ b/plugins/Events/VisitorDetails.php @@ -6,6 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * */ + namespace Piwik\Plugins\Events; use Piwik\Plugins\Live\VisitorDetailsAbstract; @@ -14,12 +15,29 @@ use Piwik\View; class VisitorDetails extends VisitorDetailsAbstract { + const EVENT_VALUE_PRECISION = 3; + public function extendActionDetails(&$action, $nextAction, $visitorDetails) { - if ($action['type'] == Action::TYPE_EVENT) { + if (!empty($action['eventType'])) { $action['type'] = 'event'; $action['icon'] = 'plugins/Morpheus/images/event.png'; + + if (strlen($action['pageTitle']) > 0) { + $action['eventName'] = $action['pageTitle']; + } + + if (isset($action['custom_float']) && strlen($action['custom_float']) > 0) { + $action['eventValue'] = round($action['custom_float'], self::EVENT_VALUE_PRECISION); + } + + unset($action['pageTitle']); + unset($action['custom_float']); + } else { + unset($action['eventCategory']); + unset($action['eventAction']); } + unset($action['eventType']); } public function extendVisitorDetails(&$visitor) |