diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php index 7d1645ca2fa..c3ce4307c10 100644 --- a/core/Db/Schema/Mysql.php +++ b/core/Db/Schema/Mysql.php @@ -148,10 +148,6 @@ public function getTablesCreateSql() idvisit INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT, idsite INTEGER(10) UNSIGNED NOT NULL, idvisitor BINARY(8) NOT NULL, - visitor_returning TINYINT(1) NOT NULL, - visit_total_time SMALLINT(5) UNSIGNED NOT NULL, - visit_goal_converted TINYINT(1) NOT NULL, - visit_goal_buyer TINYINT(1) NOT NULL, visit_last_action_time DATETIME NOT NULL, config_id BINARY(8) NOT NULL, config_pdf TINYINT(1) NOT NULL, @@ -165,11 +161,6 @@ public function getTablesCreateSql() config_silverlight TINYINT(1) NOT NULL, config_cookie TINYINT(1) NOT NULL, location_ip VARBINARY(16) NOT NULL, - location_country CHAR(3) NOT NULL, - location_region char(2) DEFAULT NULL, - location_city varchar(255) DEFAULT NULL, - location_latitude float(10, 6) DEFAULT NULL, - location_longitude float(10, 6) DEFAULT NULL, PRIMARY KEY(idvisit), INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time), INDEX index_idsite_datetime (idsite, visit_last_action_time), diff --git a/core/Plugin/ActionDimension.php b/core/Plugin/ActionDimension.php index 9b871ef58c2..f42dfb0eb2a 100644 --- a/core/Plugin/ActionDimension.php +++ b/core/Plugin/ActionDimension.php @@ -15,6 +15,7 @@ /** * @api + * @since 2.4.0 */ abstract class ActionDimension { diff --git a/core/Plugin/Menu.php b/core/Plugin/Menu.php index 72a7f675ddb..e7caceb3077 100644 --- a/core/Plugin/Menu.php +++ b/core/Plugin/Menu.php @@ -23,6 +23,7 @@ * For an example, see the {@link https://github.com/piwik/piwik/blob/master/plugins/ExampleUI/Menu.php} plugin. * * @api + * @since 2.4.0 */ class Menu { diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index c47f2ce5ec2..2a38d27ef24 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -17,6 +17,10 @@ use Piwik\WidgetsList; use Piwik\ViewDataTable\Factory as ViewDataTableFactory; +/** + * @api + * @since 2.4.0 + */ class Report { protected $module; @@ -28,6 +32,7 @@ class Report protected $widgetParams = array(); protected $menuTitle; protected $processedMetrics = array(); + protected $hasGoalMetrics = false; protected $metrics = array(); protected $constantRowsCount = null; protected $isSubtableReport = null; @@ -85,7 +90,7 @@ public function render() $apiAction = $apiProxy->buildApiActionName($this->module, $this->action); - $view = ViewDataTableFactory::build(null, $apiAction, 'CoreHome.renderWidget'); + $view = ViewDataTableFactory::build(null, $apiAction, 'CoreHome.renderMenuReport'); $rendered = $view->render(); return $rendered; @@ -115,7 +120,7 @@ public function configureReportingMenu(MenuReporting $menu) } } - protected function getMetrics() + public function getMetrics() { // TODO cache this $translations = Metrics::getDefaultMetricTranslations(); @@ -147,13 +152,18 @@ protected function getMetricsDocumentation() return $documentation; } + public function hasGoalMetrics() + { + return $this->hasGoalMetrics; + } + public function toArray() { $report = array( - 'category' => Piwik::translate($this->category), - 'name' => $this->name, - 'module' => $this->module, - 'action' => $this->action + 'category' => $this->getCategory(), + 'name' => $this->getName(), + 'module' => $this->getModule(), + 'action' => $this->getAction() ); if (!empty($this->dimension)) { @@ -185,6 +195,14 @@ public function toArray() return $report; } + /** + * @return Report[] + */ + public function getRelatedReports() + { + return array(); + } + public function getName() { return $this->name; @@ -195,6 +213,16 @@ public function getAction() return $this->action; } + public function getCategory() + { + return Piwik::translate($this->category); + } + + public function getModule() + { + return $this->module; + } + public static function factory($module, $action = '') { foreach (self::getAllReports() as $report) { diff --git a/core/Plugin/Segment.php b/core/Plugin/Segment.php index ea507f33afa..d4135a7965c 100644 --- a/core/Plugin/Segment.php +++ b/core/Plugin/Segment.php @@ -10,6 +10,7 @@ /** * @api + * @since 2.4.0 */ class Segment { @@ -39,7 +40,7 @@ protected function init() /** * @param string $acceptValues */ - public function setAcceptValues($acceptValues) + public function setAcceptedValues($acceptValues) { $this->acceptValues = $acceptValues; } diff --git a/core/Plugin/ViewDataTable.php b/core/Plugin/ViewDataTable.php index 56304762c48..b72dd1aad36 100644 --- a/core/Plugin/ViewDataTable.php +++ b/core/Plugin/ViewDataTable.php @@ -194,6 +194,22 @@ public function __construct($controllerAction, $apiMethodToRequestDataTable, $ov $report = Report::factory($this->requestConfig->getApiModuleToRequest(), $this->requestConfig->getApiMethodToRequest()); if (!empty($report)) { + $this->config->subtable_controller_action = 'renderWidget'; + $relatedReports = $report->getRelatedReports(); + if (!empty($relatedReports)) { + foreach ($relatedReports as $relatedReport) { + $params = array('reportModule' => $relatedReport->getModule(), 'reportAction' => $relatedReport->getAction()); + $this->config->addRelatedReport('CoreHome.renderWidget', + $relatedReport->getName(), + $params); + } + } + + $metrics = $report->getMetrics(); + if (!empty($metrics)) { + $this->config->addTranslations($metrics); + } + $report->configureView($this); } diff --git a/core/Plugin/VisitDimension.php b/core/Plugin/VisitDimension.php index def111f489c..d8434f9ee97 100644 --- a/core/Plugin/VisitDimension.php +++ b/core/Plugin/VisitDimension.php @@ -15,6 +15,7 @@ /** * @api + * @since 2.4.0 */ abstract class VisitDimension { diff --git a/core/Settings/SystemSetting.php b/core/Settings/SystemSetting.php index 8ca6a347cc8..35878da8ed4 100644 --- a/core/Settings/SystemSetting.php +++ b/core/Settings/SystemSetting.php @@ -27,6 +27,7 @@ class SystemSetting extends Setting * readable by everyone. * * @var bool + * @since 2.4.0 */ public $readableByCurrentUser = false; diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index df551e7d823..0f62596b406 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -300,6 +300,11 @@ public function getParam($name) return $value; } + public function getParams() + { + return $this->params; + } + public function getCurrentTimestamp() { return $this->timestamp; @@ -518,31 +523,6 @@ public function getForcedVisitorId() return $this->forcedVisitorId; } - public function overrideLocation(&$visitorInfo) - { - if (!$this->isAuthenticated()) { - return; - } - - // check for location override query parameters (ie, lat, long, country, region, city) - static $locationOverrideParams = array( - 'country' => array('string', 'location_country'), - 'region' => array('string', 'location_region'), - 'city' => array('string', 'location_city'), - 'lat' => array('float', 'location_latitude'), - 'long' => array('float', 'location_longitude'), - ); - foreach ($locationOverrideParams as $queryParamName => $info) { - list($type, $visitorInfoKey) = $info; - - $value = Common::getRequestVar($queryParamName, false, $type, $this->params); - if (!empty($value)) { - $visitorInfo[$visitorInfoKey] = $value; - } - } - return; - } - public function getPlugins() { static $pluginsInOrder = array('fla', 'java', 'dir', 'qt', 'realp', 'pdf', 'wma', 'gears', 'ag', 'cookie'); diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index da374d4daba..79cd857358f 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -49,7 +49,6 @@ class Visit implements VisitInterface */ protected $userSettings; protected $visitorCustomVariables = array(); - protected $visitorKnown; /** * @param Request $request @@ -146,7 +145,6 @@ public function handle() $visitor = new Visitor($this->request, $this->getSettingsObject(), $this->visitorInfo, $this->visitorCustomVariables); $visitor->recognize(); - $this->visitorKnown = $visitor->isVisitorKnown(); $this->visitorInfo = $visitor->getVisitorInfo(); $isLastActionInTheSameVisit = $this->isLastActionInTheSameVisit(); @@ -161,13 +159,13 @@ public function handle() // ) // AND // - the last page view for this visitor was less than 30 minutes ago @see isLastActionInTheSameVisit() - if ($this->isVisitorKnown() + if ($visitor->isVisitorKnown() && $isLastActionInTheSameVisit ) { $idReferrerActionUrl = $this->visitorInfo['visit_exit_idaction_url']; $idReferrerActionName = $this->visitorInfo['visit_exit_idaction_name']; try { - $this->handleExistingVisit($action, $visitIsConverted); + $this->handleExistingVisit($visitor, $action, $visitIsConverted); if (!is_null($action)) { $action->record($this->visitorInfo['idvisit'], $this->visitorInfo['idvisitor'], @@ -191,7 +189,7 @@ public function handle() } // When the row wasn't found in the logs, and this is a pageview or // goal matching URL, we force a new visitor else { - $this->visitorKnown = false; + $visitor->setIsVisitorKonwn(false); } } } @@ -200,10 +198,10 @@ public function handle() // - the visitor has the Piwik cookie but the last action was performed more than 30 min ago @see isLastActionInTheSameVisit() // - the visitor doesn't have the Piwik cookie, and couldn't be matched in @see recognizeTheVisitor() // - the visitor does have the Piwik cookie but the idcookie and idvisit found in the cookie didn't match to any existing visit in the DB - if (!$this->isVisitorKnown() + if (!$visitor->isVisitorKnown() || !$isLastActionInTheSameVisit ) { - $this->handleNewVisit($action, $visitIsConverted); + $this->handleNewVisit($visitor, $action, $visitIsConverted); if (!is_null($action)) { $action->record($this->visitorInfo['idvisit'], $this->visitorInfo['idvisitor'], 0, 0, 0); } @@ -231,20 +229,19 @@ public function handle() * 1) Insert the new action * 2) Update the visit information * + * @param Visitor $visitor * @param Action $action * @param $visitIsConverted * @throws VisitorNotFoundInDb */ - protected function handleExistingVisit($action, $visitIsConverted) + protected function handleExistingVisit($visitor, $action, $visitIsConverted) { Common::printDebug("Visit is known (IP = " . IP::N2P($this->getVisitorIp()) . ")"); - $valuesToUpdate = $this->getExistingVisitFieldsToUpdate($action, $visitIsConverted); + $valuesToUpdate = $this->getExistingVisitFieldsToUpdate($visitor, $action, $visitIsConverted); $this->visitorInfo['time_spent_ref_action'] = $this->getTimeSpentReferrerAction(); - $this->request->overrideLocation($valuesToUpdate); - // update visitorInfo foreach ($valuesToUpdate AS $name => $value) { $this->visitorInfo[$name] = $value; @@ -287,26 +284,26 @@ protected function getTimeSpentReferrerAction() * * 2) Insert the visit information * + * @param Visitor $visitor * @param Action $action * @param bool $visitIsConverted */ - protected function handleNewVisit($action, $visitIsConverted) + protected function handleNewVisit($visitor, $action, $visitIsConverted) { Common::printDebug("New Visit (IP = " . IP::N2P($this->getVisitorIp()) . ")"); - $this->visitorInfo = $this->getNewVisitorInformation($action); + $idVisitor = $this->getVisitorIdcookie($visitor); + $this->visitorInfo = $this->getNewVisitorInformation($idVisitor); // Add Custom variable key,value to the visitor array $this->visitorInfo = array_merge($this->visitorInfo, $this->visitorCustomVariables); - $this->visitorInfo['visit_goal_converted'] = $visitIsConverted ? 1 : 0; - $dimensions = VisitDimension::getAllDimensions(); - foreach ($dimensions as $dimension) { - if (!method_exists($dimension, 'onNewVisit')) { - continue; - } - $this->visitorInfo[$dimension->getFieldName()] = $dimension->onNewVisit($this->request, $this->visitorInfo, $action); + + $this->triggerHookOnDimensions($dimensions, 'onNewVisit', $visitor, $action); + + if ($visitIsConverted) { + $this->triggerHookOnDimensions($dimensions, 'onConvertedVisit', $visitor, $action); } /** @@ -321,7 +318,6 @@ protected function handleNewVisit($action, $visitIsConverted) */ Piwik::postEvent('Tracker.newVisitorInformation', array(&$this->visitorInfo, $this->request)); - $this->request->overrideLocation($this->visitorInfo); $this->printVisitorInformation(); $idVisit = $this->insertNewVisit( $this->visitorInfo ); @@ -331,35 +327,24 @@ protected function handleNewVisit($action, $visitIsConverted) $this->visitorInfo['visit_last_action_time'] = $this->request->getCurrentTimestamp(); } - static private function cleanupVisitTotalTime($t) - { - $t = (int)$t; - if ($t < 0) { - $t = 0; - } - $smallintMysqlLimit = 65534; - if ($t > $smallintMysqlLimit) { - $t = $smallintMysqlLimit; - } - return $t; - } - /** * Returns visitor cookie * * @return string binary */ - protected function getVisitorIdcookie() + protected function getVisitorIdcookie(Visitor $visitor) { - if ($this->isVisitorKnown()) { + if ($visitor->isVisitorKnown()) { return $this->visitorInfo['idvisitor']; } + // If the visitor had a first party ID cookie, then we use this value if (!empty($this->visitorInfo['idvisitor']) && strlen($this->visitorInfo['idvisitor']) == Tracker::LENGTH_BINARY_ID ) { return $this->visitorInfo['idvisitor']; } + return Common::hex2bin($this->generateUniqueVisitorId()); } @@ -406,15 +391,6 @@ protected function isLastActionInTheSameVisit() > ($this->request->getCurrentTimestamp() - Config::getInstance()->Tracker['visit_standard_length'])); } - /** - * Returns true if the recognizeTheVisitor() method did recognize the visitor - * @return bool - */ - protected function isVisitorKnown() - { - return $this->visitorKnown === true; - } - // is the referrer host any of the registered URLs for this website? static public function isHostKnownAliasHost($urlHost, $idSite) { @@ -502,31 +478,12 @@ protected function printVisitorInformation() Common::printDebug($debugVisitInfo); } - protected function getNewVisitorInformation($action) + protected function getNewVisitorInformation($idVisitor) { - $visitCount = $this->request->getVisitCount(); - $daysSinceLastVisit = $this->request->getDaysSinceLastVisit(); - - $daysSinceLastOrder = $this->request->getDaysSinceLastOrder(); - $isReturningCustomer = ($daysSinceLastOrder !== false); - - // User settings - $userInfo = $this->getSettingsObject(); - $userInfo = $userInfo->getInfo(); - - $visitorReturning = $isReturningCustomer - ? 2 /* Returning customer */ - : ($visitCount > 1 || $this->isVisitorKnown() || $daysSinceLastVisit > 0 - ? 1 /* Returning */ - : 0 /* New */); - $defaultTimeOnePageVisit = Config::getInstance()->Tracker['default_time_one_page_visit']; + $userInfo = $this->getSettingsObject()->getInfo(); return array( - 'idsite' => $this->request->getIdSite(), - 'idvisitor' => $this->getVisitorIdcookie(), - 'visitor_returning' => $visitorReturning, - 'visit_total_time' => self::cleanupVisitTotalTime($defaultTimeOnePageVisit), - 'visit_goal_buyer' => $this->goalManager->getBuyerType(), + 'idvisitor' => $idVisitor, 'config_id' => $userInfo['config_id'], 'config_pdf' => $userInfo['config_pdf'], 'config_flash' => $userInfo['config_flash'], @@ -545,59 +502,62 @@ protected function getNewVisitorInformation($action) /** * Gather fields=>values that needs to be updated for the existing visit in log_visit * - * @param $action + * @param Visitor $visitor + * @param Action|null $action * @param $visitIsConverted * @return array */ - protected function getExistingVisitFieldsToUpdate($action, $visitIsConverted) + protected function getExistingVisitFieldsToUpdate($visitor, $action, $visitIsConverted) { $valuesToUpdate = array(); - // Add 1 so it's always > 0 - $visitTotalTime = 1 + $this->request->getCurrentTimestamp() - $this->visitorInfo['visit_first_action_time']; - $valuesToUpdate['visit_total_time'] = self::cleanupVisitTotalTime($visitTotalTime); - - // Goal conversion - if ($visitIsConverted) { - $valuesToUpdate['visit_goal_converted'] = 1; - // If a pageview and goal conversion in the same second, with previously a goal conversion recorded - // the request would not "update" the row since all values are the same as previous - // therefore the request below throws exception, instead we make sure the UPDATE will affect the row - $valuesToUpdate['visit_total_time'] = self::cleanupVisitTotalTime( - $valuesToUpdate['visit_total_time'] - + $this->goalManager->idGoal - // +2 to offset idgoal=-1 and idgoal=0 - + 2); - } - // Might update the idvisitor when it was forced or overwritten for this visit if (strlen($this->visitorInfo['idvisitor']) == Tracker::LENGTH_BINARY_ID) { $valuesToUpdate['idvisitor'] = $this->visitorInfo['idvisitor']; } - // Ecommerce buyer status - $visitEcommerceStatus = $this->goalManager->getBuyerType($this->visitorInfo['visit_goal_buyer']); + $dimensions = VisitDimension::getAllDimensions(); + $valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onExistingVisit', $visitor, $action, $valuesToUpdate); - if($visitEcommerceStatus != GoalManager::TYPE_BUYER_NONE - // only update if the value has changed (prevents overwriting the value in case a request has updated it in the meantime) - && $visitEcommerceStatus != $this->visitorInfo['visit_goal_buyer']) { - $valuesToUpdate['visit_goal_buyer'] = $visitEcommerceStatus; + if ($visitIsConverted) { + $valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onConvertedVisit', $visitor, $action, $valuesToUpdate); } - $dimensions = VisitDimension::getAllDimensions(); + // Custom Variables overwrite previous values on each page view + $valuesToUpdate = array_merge($valuesToUpdate, $this->visitorCustomVariables); + return $valuesToUpdate; + } + + /** + * @param VisitDimension[] $dimensions + * @param string $hook + * @param Visitor $visitor + * @param Action|null $action + * @param array|null $valuesToUpdate If null, $this->visitorInfo will be updated + * + * @return array|null The updated $valuesToUpdate or null if no $valuesToUpdate given + */ + private function triggerHookOnDimensions($dimensions, $hook, $visitor, $action, $valuesToUpdate = null) + { foreach ($dimensions as $dimension) { - if (!method_exists($dimension, 'onExistingVisit')) { + if (!method_exists($dimension, $hook)) { continue; } - $value = $dimension->onExistingVisit($this->request, $this->visitorInfo, $action); - if (false !== $value) { - $valuesToUpdate[$dimension->getFieldName()] = $value; + $value = $dimension->$hook($this->request, $visitor, $action); + + if ($value !== false) { + $fieldName = $dimension->getFieldName(); + $visitor->setVisitorColumn($fieldName, $value); + + if ($valuesToUpdate !== null) { + $valuesToUpdate[$fieldName] = $value; + } else { + $this->visitorInfo[$fieldName] = $value; + } } } - // Custom Variables overwrite previous values on each page view - $valuesToUpdate = array_merge($valuesToUpdate, $this->visitorCustomVariables); return $valuesToUpdate; } } diff --git a/core/Tracker/Visitor.php b/core/Tracker/Visitor.php index 19ac7171e46..8839c30a5bd 100644 --- a/core/Tracker/Visitor.php +++ b/core/Tracker/Visitor.php @@ -10,13 +10,19 @@ use Piwik\Common; use Piwik\Config; +use Piwik\Plugin\VisitDimension; use Piwik\Plugins\CustomVariables\CustomVariables; use Piwik\Piwik; use Piwik\Tracker; class Visitor { - function __construct(Request $request, Tracker\Settings $settings, $visitorInfo = array(), $customVariables = null) + private $visitorKnown = false; + private $request; + private $visitorInfo; + private $userInfo; + + public function __construct(Request $request, Tracker\Settings $settings, $visitorInfo = array(), $customVariables = null) { $this->request = $request; $this->visitorInfo = $visitorInfo; @@ -31,9 +37,9 @@ function __construct(Request $request, Tracker\Settings $settings, $visitorInfo * - Known visitor * - New visitor */ - function recognize() + public function recognize() { - $this->visitorKnown = false; + $this->setIsVisitorKonwn(false); $configId = $this->userInfo['config_id']; @@ -58,12 +64,13 @@ function recognize() } $persistedVisitAttributes = self::getVisitFieldsPersist(); + array_unshift($persistedVisitAttributes, 'visit_first_action_time'); + array_unshift($persistedVisitAttributes, 'visit_last_action_time'); + $persistedVisitAttributes = array_unique($persistedVisitAttributes); $selectFields = implode(", ", $persistedVisitAttributes); $select = "SELECT - visit_last_action_time, - visit_first_action_time, $selectFields $selectCustomVariables "; @@ -155,14 +162,15 @@ function recognize() && $visitRow && count($visitRow) > 0 ) { - // These values will be used throughout the request - $this->visitorInfo['visit_last_action_time'] = strtotime($visitRow['visit_last_action_time']); - $this->visitorInfo['visit_first_action_time'] = strtotime($visitRow['visit_first_action_time']); + // These values will be used throughout the request foreach($persistedVisitAttributes as $field) { $this->visitorInfo[$field] = $visitRow[$field]; } + $this->visitorInfo['visit_last_action_time'] = strtotime($visitRow['visit_last_action_time']); + $this->visitorInfo['visit_first_action_time'] = strtotime($visitRow['visit_first_action_time']); + // Custom Variables copied from Visit in potential later conversion if (!empty($selectCustomVariables)) { $maxCustomVariables = CustomVariables::getMaxCustomVariables(); @@ -180,7 +188,7 @@ function recognize() } } - $this->visitorKnown = true; + $this->setIsVisitorKonwn(true); Common::printDebug("The visitor is known (idvisitor = " . bin2hex($this->visitorInfo['idvisitor']) . ", config_id = " . bin2hex($configId) . ", idvisit = {$this->visitorInfo['idvisit']}, @@ -248,7 +256,6 @@ public static function getVisitFieldsPersist() 'visitor_days_since_first', 'visitor_days_since_order', 'visitor_count_visits', - 'visit_goal_buyer', 'location_country', 'location_region', @@ -261,36 +268,64 @@ public static function getVisitFieldsPersist() 'referer_type', ); + $dimensions = VisitDimension::getAllDimensions(); + foreach ($dimensions as $dimension) { + if (method_exists($dimension, 'onExistingVisit')) { + $fields[] = $dimension->getFieldName(); + } + + + /** + * This event collects a list of [visit entity]() properties that should be loaded when reading + * the existing visit. Properties that appear in this list will be available in other tracking + * events such as 'onExistingVisit'. + * + * Plugins can use this event to load additional visit entity properties for later use during tracking. + * + * This way all dimensions cannot only make sure the column values are loaded that they need, we can later + * even implement to resolve required dimensions before the defining dimension is resolved. + */ + if (method_exists($dimension, 'getRequiredVisitFields')) { + foreach ($dimension->getRequiredVisitFields() as $field) { + $fields[] = $field; + } + } + } + /** - * Triggered when checking if the current action being tracked belongs to an existing visit. - * - * This event collects a list of [visit entity]() properties that should be loaded when reading - * the existing visit. Properties that appear in this list will be available in other tracking - * events such as {@hook Tracker.newConversionInformation} and {@hook Tracker.newVisitorInformation}. - * - * Plugins can use this event to load additional visit entity properties for later use during tracking. - * When you add fields to this $fields array, they will be later available in Tracker.newConversionInformation - * - * **Example** - * - * Piwik::addAction('Tracker.getVisitFieldsToPersist', function (&$fields) { - * $fields[] = 'custom_visit_property'; - * }); - * - * @param array &$fields The list of visit properties to load. + * @ignore */ Piwik::postEvent('Tracker.getVisitFieldsToPersist', array(&$fields)); return $fields; } - function getVisitorInfo() + public function getVisitorInfo() { return $this->visitorInfo; } - function isVisitorKnown() + public function setVisitorColumn($column, $value) + { + $this->visitorInfo[$column] = $value; + } + + public function getVisitorColumn($column) + { + if (array_key_exists($column, $this->visitorInfo)) { + return $this->visitorInfo[$column]; + } + + return false; + } + + public function isVisitorKnown() { return $this->visitorKnown === true; } + + public function setIsVisitorKonwn($isVisitorKnown) + { + return $this->visitorKnown = $isVisitorKnown; + } } diff --git a/core/ViewDataTable/Factory.php b/core/ViewDataTable/Factory.php index 3b53dd739ff..8c03a54a299 100644 --- a/core/ViewDataTable/Factory.php +++ b/core/ViewDataTable/Factory.php @@ -107,6 +107,7 @@ public static function build($defaultType = null, $apiAction = false, $controlle $params = array(); } else { $login = Piwik::getCurrentUserLogin(); + // TODO this won't work as currently all reports use CoreHome.renderMenuReport $params = Manager::getViewDataTableParameters($login, $controllerAction); } diff --git a/plugins/API/API.php b/plugins/API/API.php index 8af6471353d..76a2e7a6008 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -180,58 +180,6 @@ public function getSegmentsMetadata($idSites = array(), $_hideImplementationData 'sqlFilterValue' => array('Piwik\IP', 'P2N'), 'permission' => $isAuthenticatedWithViewAccess, ); - $segments[] = array( - 'type' => 'metric', - 'category' => Piwik::translate('General_Visit'), - 'name' => 'General_ColumnVisitDuration', - 'segment' => 'visitDuration', - 'sqlSegment' => 'log_visit.visit_total_time', - ); - $segments[] = array( - 'type' => 'dimension', - 'category' => Piwik::translate('General_Visit'), - 'name' => Piwik::translate('General_VisitType'), - 'segment' => 'visitorType', - 'acceptedValues' => 'new, returning, returningCustomer' . ". " . Piwik::translate('General_VisitTypeExample', '"&segment=visitorType==returning,visitorType==returningCustomer"'), - 'sqlSegment' => 'log_visit.visitor_returning', - 'sqlFilterValue' => function ($type) { - return $type == "new" ? 0 : ($type == "returning" ? 1 : 2); - } - ); - $segments[] = array( - 'type' => 'metric', - 'category' => Piwik::translate('General_Visit'), - 'name' => 'General_DaysSinceLastVisit', - 'segment' => 'daysSinceLastVisit', - 'sqlSegment' => 'log_visit.visitor_days_since_last', - ); - $segments[] = array( - 'type' => 'dimension', - 'category' => Piwik::translate('General_Visit'), - 'name' => 'General_VisitConvertedGoal', - 'segment' => 'visitConverted', - 'acceptedValues' => '0, 1', - 'sqlSegment' => 'log_visit.visit_goal_converted', - ); - - $segments[] = array( - 'type' => 'dimension', - 'category' => Piwik::translate('General_Visit'), - 'name' => Piwik::translate('General_EcommerceVisitStatusDesc'), - 'segment' => 'visitEcommerceStatus', - 'acceptedValues' => implode(", ", self::$visitEcommerceStatus) - . '. ' . Piwik::translate('General_EcommerceVisitStatusEg', '"&segment=visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart"'), - 'sqlSegment' => 'log_visit.visit_goal_buyer', - 'sqlFilterValue' => __NAMESPACE__ . '\API::getVisitEcommerceStatus', - ); - - $segments[] = array( - 'type' => 'metric', - 'category' => Piwik::translate('General_Visit'), - 'name' => 'General_DaysSinceLastEcommerceOrder', - 'segment' => 'daysSinceLastEcommerceOrder', - 'sqlSegment' => 'log_visit.visitor_days_since_order', - ); foreach ($segments as &$segment) { $segment['name'] = Piwik::translate($segment['name']); @@ -248,36 +196,6 @@ public function getSegmentsMetadata($idSites = array(), $_hideImplementationData return $segments; } - static protected $visitEcommerceStatus = array( - GoalManager::TYPE_BUYER_NONE => 'none', - GoalManager::TYPE_BUYER_ORDERED => 'ordered', - GoalManager::TYPE_BUYER_OPEN_CART => 'abandonedCart', - GoalManager::TYPE_BUYER_ORDERED_AND_OPEN_CART => 'orderedThenAbandonedCart', - ); - - /** - * @ignore - */ - static public function getVisitEcommerceStatusFromId($id) - { - if (!isset(self::$visitEcommerceStatus[$id])) { - throw new \Exception("Unexpected ECommerce status value "); - } - return self::$visitEcommerceStatus[$id]; - } - - /** - * @ignore - */ - static public function getVisitEcommerceStatus($status) - { - $id = array_search($status, self::$visitEcommerceStatus); - if ($id === false) { - throw new \Exception("Invalid 'visitEcommerceStatus' segment value $status"); - } - return $id; - } - private function sortSegments($row1, $row2) { $columns = array('type', 'category', 'name', 'segment'); diff --git a/plugins/Actions/Columns/EntryPageTitle.php b/plugins/Actions/Columns/EntryPageTitle.php index 5664ea7c217..47045f13cfb 100644 --- a/plugins/Actions/Columns/EntryPageTitle.php +++ b/plugins/Actions/Columns/EntryPageTitle.php @@ -13,6 +13,7 @@ use Piwik\Plugin\VisitDimension; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class EntryPageTitle extends VisitDimension { @@ -29,11 +30,11 @@ protected function init() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { $idActionName = false; diff --git a/plugins/Actions/Columns/EntryPageUrl.php b/plugins/Actions/Columns/EntryPageUrl.php index 760f4b635a9..5c89117df3b 100644 --- a/plugins/Actions/Columns/EntryPageUrl.php +++ b/plugins/Actions/Columns/EntryPageUrl.php @@ -13,6 +13,7 @@ use Piwik\Plugin\VisitDimension; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class EntryPageUrl extends VisitDimension { @@ -29,11 +30,11 @@ protected function init() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { $idActionUrl = false; diff --git a/plugins/Actions/Columns/ExitPageTitle.php b/plugins/Actions/Columns/ExitPageTitle.php index 2f2054ac608..c606035fb3b 100644 --- a/plugins/Actions/Columns/ExitPageTitle.php +++ b/plugins/Actions/Columns/ExitPageTitle.php @@ -13,6 +13,7 @@ use Piwik\Plugin\VisitDimension; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class ExitPageTitle extends VisitDimension { @@ -29,11 +30,11 @@ protected function init() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int|bool */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { $idActionName = false; @@ -46,11 +47,11 @@ public function onNewVisit(Request $request, $visit, $action) /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int|bool */ - public function onExistingVisit(Request $request, $visit, $action) + public function onExistingVisit(Request $request, Visitor $visitor, $action) { if (empty($action)) { return false; diff --git a/plugins/Actions/Columns/ExitPageUrl.php b/plugins/Actions/Columns/ExitPageUrl.php index 82ad5c598ae..b85e26ad509 100644 --- a/plugins/Actions/Columns/ExitPageUrl.php +++ b/plugins/Actions/Columns/ExitPageUrl.php @@ -13,6 +13,7 @@ use Piwik\Plugin\VisitDimension; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class ExitPageUrl extends VisitDimension { @@ -29,11 +30,11 @@ protected function init() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int|bool */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { $idActionUrl = false; @@ -44,7 +45,13 @@ public function onNewVisit(Request $request, $visit, $action) return (int) $idActionUrl; } - public function onExistingVisit(Request $request, $visit, $action) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) { if (empty($action)) { return false; diff --git a/plugins/Actions/Columns/PageUrl.php b/plugins/Actions/Columns/PageUrl.php index 0d0d5504f46..56d21e6ed1a 100644 --- a/plugins/Actions/Columns/PageUrl.php +++ b/plugins/Actions/Columns/PageUrl.php @@ -22,7 +22,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('pageUrl'); $segment->setName('Actions_ColumnPageURL'); - $segment->setAcceptValues('All these segments must be URL encoded, for example: ' . urlencode('http://example.com/path/page?query')); + $segment->setAcceptedValues('All these segments must be URL encoded, for example: ' . urlencode('http://example.com/path/page?query')); $this->addSegment($segment); } @@ -30,15 +30,4 @@ public function getName() { return Piwik::translate('Actions_ColumnPageURL'); } - - /* - public function shouldHandleAction(Request $request) - { - return true; - } - - public function getActionId() - { - return 1; - }*/ } diff --git a/plugins/Actions/Columns/VisitTotalActions.php b/plugins/Actions/Columns/VisitTotalActions.php index 49177a3143b..5705d822f0b 100644 --- a/plugins/Actions/Columns/VisitTotalActions.php +++ b/plugins/Actions/Columns/VisitTotalActions.php @@ -13,6 +13,7 @@ use Piwik\Tracker\Action; use Piwik\Tracker\Request; use Piwik\Tracker; +use Piwik\Tracker\Visitor; class VisitTotalActions extends VisitDimension { @@ -35,11 +36,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { $actionType = false; if ($action) { @@ -64,11 +65,11 @@ public function onNewVisit(Request $request, $visit, $action) /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int */ - public function onExistingVisit(Request $request, $visit, $action) + public function onExistingVisit(Request $request, Visitor $visitor, $action) { if (!$action) { return false; diff --git a/plugins/Actions/Columns/VisitTotalSearches.php b/plugins/Actions/Columns/VisitTotalSearches.php index 42a9ac8b14f..ca09132bce0 100644 --- a/plugins/Actions/Columns/VisitTotalSearches.php +++ b/plugins/Actions/Columns/VisitTotalSearches.php @@ -13,6 +13,7 @@ use Piwik\Tracker\Action; use Piwik\Tracker\Request; use Piwik\Tracker; +use Piwik\Tracker\Visitor; class VisitTotalSearches extends VisitDimension { @@ -25,7 +26,7 @@ protected function init() $segment->setType(Segment::TYPE_METRIC); $segment->setSegment('searches'); $segment->setName('General_NbSearches'); - $segment->setAcceptValues('To select all visits who used internal Site Search, use: &segment=searches>0'); + $segment->setAcceptedValues('To select all visits who used internal Site Search, use: &segment=searches>0'); $this->addSegment($segment); } @@ -36,11 +37,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { if ($this->isSiteSearchAction($action)) { return 1; @@ -51,11 +52,11 @@ public function onNewVisit(Request $request, $visit, $action) /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int */ - public function onExistingVisit(Request $request, $visit, $action) + public function onExistingVisit(Request $request, Visitor $visitor, $action) { if ($this->isSiteSearchAction($action)) { return 'visit_total_searches + 1'; diff --git a/plugins/Actions/Reports/GetDownloads.php b/plugins/Actions/Reports/GetDownloads.php index 1722142083d..099fcb271b0 100644 --- a/plugins/Actions/Reports/GetDownloads.php +++ b/plugins/Actions/Reports/GetDownloads.php @@ -30,7 +30,7 @@ protected function init() $this->widgetTitle = 'General_Downloads'; } - protected function getMetrics() + public function getMetrics() { return array( 'nb_visits' => Piwik::translate('Actions_ColumnUniqueDownloads'), @@ -48,11 +48,7 @@ protected function getMetricsDocumentation() public function configureView(ViewDataTable $view) { - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'nb_visits' => Piwik::translate('Actions_ColumnUniqueDownloads'), - 'nb_hits' => Piwik::translate('General_Downloads'), - )); + $view->config->addTranslations(array('label' => $this->dimension->getName())); $view->config->columns_to_display = array('label', 'nb_visits', 'nb_hits'); $view->config->show_exclude_low_population = false; diff --git a/plugins/Actions/Reports/GetEntryPageTitles.php b/plugins/Actions/Reports/GetEntryPageTitles.php index a1af47c94dc..88778ebacf9 100644 --- a/plugins/Actions/Reports/GetEntryPageTitles.php +++ b/plugins/Actions/Reports/GetEntryPageTitles.php @@ -10,11 +10,8 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\Actions\API; -use Piwik\API\Request; use Piwik\Common; use Piwik\Plugins\Actions\Columns\EntryPageTitle; -use Piwik\Plugins\Actions\Columns\PageTitle; class GetEntryPageTitles extends Base { @@ -43,18 +40,7 @@ protected function getMetricsDocumentation() public function configureView(ViewDataTable $view) { - $entryPageUrlAction = - Common::getRequestVar('widget', false) === false ? 'indexEntryPageUrls' : 'getEntryPageUrls'; - - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'entry_bounce_count' => Piwik::translate('General_ColumnBounces'), - 'entry_nb_visits' => Piwik::translate('General_ColumnEntrances'), - )); - $view->config->addRelatedReports(array( - 'Actions.getPageTitles' => Piwik::translate('Actions_SubmenuPageTitles'), - "Actions.$entryPageUrlAction" => Piwik::translate('Actions_SubmenuPagesEntry') - )); + $view->config->addTranslations(array('label' => $this->dimension->getName())); $view->config->columns_to_display = array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate'); $view->config->title = $this->name; diff --git a/plugins/Actions/Reports/GetEntryPageUrls.php b/plugins/Actions/Reports/GetEntryPageUrls.php index dc86ad7f965..659887b15d3 100644 --- a/plugins/Actions/Reports/GetEntryPageUrls.php +++ b/plugins/Actions/Reports/GetEntryPageUrls.php @@ -11,10 +11,8 @@ use Piwik\Common; use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\Actions\API; use Piwik\API\Request; use Piwik\Plugins\Actions\Columns\EntryPageUrl; -use Piwik\Plugins\Actions\Columns\PageUrl; class GetEntryPageUrls extends Base { @@ -54,14 +52,9 @@ public function configureView(ViewDataTable $view) 'action' => $widget === false ? 'indexEntryPageUrls' : 'getEntryPageUrls' )); - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'entry_bounce_count' => Piwik::translate('General_ColumnBounces'), - 'entry_nb_visits' => Piwik::translate('General_ColumnEntrances')) - ); + $view->config->addTranslations(array('label' => $this->dimension->getName())); - // $view->config->title = $this->name; - $view->config->addRelatedReport('Actions.getEntryPageTitles', Piwik::translate('Actions_EntryPageTitles')); + $view->config->title = $this->name; $view->config->columns_to_display = array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate'); $view->requestConfig->filter_sort_column = 'entry_nb_visits'; $view->requestConfig->filter_sort_order = 'desc'; diff --git a/plugins/Actions/Reports/GetExitPageTitles.php b/plugins/Actions/Reports/GetExitPageTitles.php index 2fd68fb0bd5..7f33b57df29 100644 --- a/plugins/Actions/Reports/GetExitPageTitles.php +++ b/plugins/Actions/Reports/GetExitPageTitles.php @@ -35,7 +35,7 @@ protected function init() $this->widgetTitle = 'Actions_WidgetExitPageTitles'; } - protected function getMetrics() + public function getMetrics() { $metrics = parent::getMetrics(); $metrics['nb_visits'] = Piwik::translate('General_ColumnUniquePageviews'); @@ -53,17 +53,7 @@ protected function getMetricsDocumentation() public function configureView(ViewDataTable $view) { - $exitPageUrlAction = - Common::getRequestVar('widget', false) === false ? 'indexExitPageUrls' : 'getExitPageUrls'; - - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'exit_nb_visits' => Piwik::translate('General_ColumnExits'), - )); - $view->config->addRelatedReports(array( - 'Actions.getPageTitles' => Piwik::translate('Actions_SubmenuPageTitles'), - "Actions.$exitPageUrlAction" => Piwik::translate('Actions_SubmenuPagesExit'), - )); + $view->config->addTranslations(array('label' => $this->dimension->getName())); $view->config->title = $this->name; $view->config->columns_to_display = array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate'); @@ -75,7 +65,6 @@ public function configureView(ViewDataTable $view) public function getRelatedReports() { return array( - new GetPageTitles(), new GetExitPageUrls() ); } diff --git a/plugins/Actions/Reports/GetExitPageUrls.php b/plugins/Actions/Reports/GetExitPageUrls.php index 61ffc1c82ad..c9b99f114c7 100644 --- a/plugins/Actions/Reports/GetExitPageUrls.php +++ b/plugins/Actions/Reports/GetExitPageUrls.php @@ -36,8 +36,7 @@ protected function init() $this->widgetTitle = 'Actions_WidgetPagesExit'; } - - protected function getMetrics() + public function getMetrics() { $metrics = parent::getMetrics(); $metrics['nb_visits'] = Piwik::translate('General_ColumnUniquePageviews'); @@ -63,13 +62,9 @@ public function configureView(ViewDataTable $view) 'action' => $widget === false ? 'indexExitPageUrls' : 'getExitPageUrls' )); - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'exit_nb_visits' => Piwik::translate('General_ColumnExits')) - ); + $view->config->addTranslations(array('label' => $this->dimension->getName())); $view->config->title = $this->name; - $view->config->addRelatedReport('Actions.getExitPageTitles', Piwik::translate('Actions_ExitPageTitles')); $view->config->columns_to_display = array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate'); $view->requestConfig->filter_sort_column = 'exit_nb_visits'; diff --git a/plugins/Actions/Reports/GetOutlinks.php b/plugins/Actions/Reports/GetOutlinks.php index e7abcd4f522..e8e296e2dbd 100644 --- a/plugins/Actions/Reports/GetOutlinks.php +++ b/plugins/Actions/Reports/GetOutlinks.php @@ -37,7 +37,7 @@ protected function init() $this->widgetTitle = 'General_Outlinks'; } - protected function getMetrics() + public function getMetrics() { return array( 'nb_visits' => Piwik::translate('Actions_ColumnUniqueClicks'), @@ -55,11 +55,7 @@ protected function getMetricsDocumentation() public function configureView(ViewDataTable $view) { - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'nb_visits' => Piwik::translate('Actions_ColumnUniqueClicks'), - 'nb_hits' => Piwik::translate('Actions_ColumnClicks'), - )); + $view->config->addTranslations(array('label' => $this->dimension->getName())); $view->config->columns_to_display = array('label', 'nb_visits', 'nb_hits'); $view->config->show_exclude_low_population = false; diff --git a/plugins/Actions/Reports/GetPageTitles.php b/plugins/Actions/Reports/GetPageTitles.php index 56c75ceac28..7a64a2661ea 100644 --- a/plugins/Actions/Reports/GetPageTitles.php +++ b/plugins/Actions/Reports/GetPageTitles.php @@ -35,7 +35,7 @@ protected function init() $this->widgetTitle = 'Actions_WidgetPageTitles'; } - protected function getMetrics() + public function getMetrics() { $metrics = parent::getMetrics(); $metrics['nb_visits'] = Piwik::translate('General_ColumnUniquePageviews'); @@ -58,19 +58,15 @@ public function configureView(ViewDataTable $view) $widget = Common::getRequestVar('widget', false); $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array( - 'module' => 'Actions', + 'module' => $this->module, 'action' => $widget === false ? 'indexPageTitles' : 'getPageTitles' )); $view->config->title = $this->name; - $view->config->addRelatedReports(array( - 'Actions.getEntryPageTitles' => Piwik::translate('Actions_EntryPageTitles'), - 'Actions.getExitPageTitles' => Piwik::translate('Actions_ExitPageTitles'), - )); $view->config->addTranslation('label', $this->dimension->getName()); $view->config->columns_to_display = array('label', 'nb_hits', 'nb_visits', 'bounce_rate', - 'avg_time_on_page', 'exit_rate', 'avg_time_generation'); + 'avg_time_on_page', 'exit_rate', 'avg_time_generation'); $this->addPageDisplayProperties($view); $this->addBaseDisplayProperties($view); diff --git a/plugins/Actions/Reports/GetPageTitlesFollowingSiteSearch.php b/plugins/Actions/Reports/GetPageTitlesFollowingSiteSearch.php index e69d558fc0e..be069179c1e 100644 --- a/plugins/Actions/Reports/GetPageTitlesFollowingSiteSearch.php +++ b/plugins/Actions/Reports/GetPageTitlesFollowingSiteSearch.php @@ -32,7 +32,7 @@ public function configureView(ViewDataTable $view) $this->configureViewForUrlAndTitle($view, $title); } - protected function getMetrics() + public function getMetrics() { return array( 'nb_hits_following_search' => Piwik::translate('General_ColumnViewedAfterSearch'), @@ -50,17 +50,7 @@ protected function getMetricsDocumentation() protected function configureViewForUrlAndTitle(ViewDataTable $view, $title) { - $relatedReports = array( - 'Actions.getPageTitlesFollowingSiteSearch' => Piwik::translate('Actions_WidgetPageTitlesFollowingSearch'), - 'Actions.getPageUrlsFollowingSiteSearch' => Piwik::translate('Actions_WidgetPageUrlsFollowingSearch'), - ); - - $view->config->addRelatedReports($relatedReports); - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'nb_hits_following_search' => Piwik::translate('General_ColumnViewedAfterSearch'), - 'nb_hits' => Piwik::translate('General_ColumnTotalPageviews') - )); + $view->config->addTranslations(array('label' => $this->dimension->getName())); $view->config->title = $title; $view->config->columns_to_display = array('label', 'nb_hits_following_search', 'nb_hits'); @@ -72,4 +62,10 @@ protected function configureViewForUrlAndTitle(ViewDataTable $view, $title) $this->addBaseDisplayProperties($view); } + public function getRelatedReports() + { + return array( + new GetPageUrlsFollowingSiteSearch() + ); + } } diff --git a/plugins/Actions/Reports/GetPageUrls.php b/plugins/Actions/Reports/GetPageUrls.php index f8fbd9afd6f..c8805fe408b 100644 --- a/plugins/Actions/Reports/GetPageUrls.php +++ b/plugins/Actions/Reports/GetPageUrls.php @@ -34,7 +34,7 @@ protected function init() $this->widgetTitle = 'General_Pages'; } - protected function getMetrics() + public function getMetrics() { $metrics = parent::getMetrics(); $metrics['nb_visits'] = Piwik::translate('General_ColumnUniquePageviews'); diff --git a/plugins/Actions/Reports/GetPageUrlsFollowingSiteSearch.php b/plugins/Actions/Reports/GetPageUrlsFollowingSiteSearch.php index d41380d7889..1891b929786 100644 --- a/plugins/Actions/Reports/GetPageUrlsFollowingSiteSearch.php +++ b/plugins/Actions/Reports/GetPageUrlsFollowingSiteSearch.php @@ -30,4 +30,11 @@ public function configureView(ViewDataTable $view) $this->configureViewForUrlAndTitle($view, $title); } + + public function getRelatedReports() + { + return array( + new GetPageTitlesFollowingSiteSearch() + ); + } } diff --git a/plugins/Actions/Reports/GetSiteSearchCategories.php b/plugins/Actions/Reports/GetSiteSearchCategories.php index 404457b5057..35e7421feb2 100644 --- a/plugins/Actions/Reports/GetSiteSearchCategories.php +++ b/plugins/Actions/Reports/GetSiteSearchCategories.php @@ -32,7 +32,7 @@ public function isEnabled() return parent::isEnabled() && Actions::isCustomVariablesPluginsEnabled(); } - protected function getMetrics() + public function getMetrics() { return array( 'nb_visits' => Piwik::translate('Actions_ColumnSearches'), @@ -52,11 +52,7 @@ protected function getMetricsDocumentation() public function configureView(ViewDataTable $view) { - $view->config->addTranslations(array( - 'label' => $this->dimension->getName(), - 'nb_visits' => Piwik::translate('Actions_ColumnSearches'), - 'nb_pages_per_search' => Piwik::translate('Actions_ColumnPagesPerSearch') - )); + $view->config->addTranslations(array('label' => $this->dimension->getName())); $view->config->columns_to_display = array('label', 'nb_visits', 'nb_pages_per_search'); $view->config->show_table_all_columns = false; diff --git a/plugins/Actions/Reports/GetSiteSearchKeywords.php b/plugins/Actions/Reports/GetSiteSearchKeywords.php index a3fa93dc1df..d1941c726a4 100644 --- a/plugins/Actions/Reports/GetSiteSearchKeywords.php +++ b/plugins/Actions/Reports/GetSiteSearchKeywords.php @@ -26,7 +26,7 @@ protected function init() $this->widgetTitle = 'Actions_WidgetSearchKeywords'; } - protected function getMetrics() + public function getMetrics() { return array( 'nb_visits' => Piwik::translate('Actions_ColumnSearches'), diff --git a/plugins/Actions/Reports/GetSiteSearchNoResultKeywords.php b/plugins/Actions/Reports/GetSiteSearchNoResultKeywords.php index df867917031..ee5a9968405 100644 --- a/plugins/Actions/Reports/GetSiteSearchNoResultKeywords.php +++ b/plugins/Actions/Reports/GetSiteSearchNoResultKeywords.php @@ -25,7 +25,7 @@ protected function init() $this->widgetTitle = 'Actions_WidgetSearchNoResultKeywords'; } - protected function getMetrics() + public function getMetrics() { return array( 'nb_visits' => Piwik::translate('Actions_ColumnSearches'), diff --git a/plugins/CoreHome/Columns/IdSite.php b/plugins/CoreHome/Columns/IdSite.php new file mode 100644 index 00000000000..2c29df898b0 --- /dev/null +++ b/plugins/CoreHome/Columns/IdSite.php @@ -0,0 +1,41 @@ +getIdSite(); + } +} \ No newline at end of file diff --git a/plugins/CoreHome/Columns/VisitFirstActionTime.php b/plugins/CoreHome/Columns/VisitFirstActionTime.php index e0b7078fb8f..15a8e70043f 100644 --- a/plugins/CoreHome/Columns/VisitFirstActionTime.php +++ b/plugins/CoreHome/Columns/VisitFirstActionTime.php @@ -12,6 +12,7 @@ use Piwik\Tracker\Action; use Piwik\Tracker\Request; use Piwik\Tracker; +use Piwik\Tracker\Visitor; class VisitFirstActionTime extends VisitDimension { @@ -25,11 +26,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { return Tracker::getDatetimeFromTimestamp($request->getCurrentTimestamp()); } diff --git a/plugins/CoreHome/Columns/VisitGoalBuyer.php b/plugins/CoreHome/Columns/VisitGoalBuyer.php new file mode 100644 index 00000000000..64ca106962b --- /dev/null +++ b/plugins/CoreHome/Columns/VisitGoalBuyer.php @@ -0,0 +1,106 @@ + 'none', + GoalManager::TYPE_BUYER_ORDERED => 'ordered', + GoalManager::TYPE_BUYER_OPEN_CART => 'abandonedCart', + GoalManager::TYPE_BUYER_ORDERED_AND_OPEN_CART => 'orderedThenAbandonedCart', + ); + + protected $fieldName = 'visit_goal_buyer'; + protected $fieldType = 'TINYINT(1) NOT NULL'; + + protected function init() + { + $example = Piwik::translate('General_EcommerceVisitStatusEg', '"&segment=visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart"'); + $acceptedValues = implode(", ", self::$visitEcommerceStatus) . '. ' . $example; + + $segment = new Segment(); + $segment->setSegment('visitEcommerceStatus'); + $segment->setName('General_EcommerceVisitStatusDesc'); + $segment->setAcceptedValues($acceptedValues); + $segment->setSqlFilterValue(__NAMESPACE__ . '\VisitGoalBuyer::getVisitEcommerceStatus'); + + $this->addSegment($segment); + } + + public function getName() + { + return ''; + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $goalManager = new GoalManager($request); + + return $goalManager->getBuyerType(); + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) + { + $goalBuyer = $visitor->getVisitorColumn('visit_goal_buyer'); + + // Ecommerce buyer status + $goalManager = new GoalManager($request); + $visitEcommerceStatus = $goalManager->getBuyerType($goalBuyer); + + if($visitEcommerceStatus != GoalManager::TYPE_BUYER_NONE + // only update if the value has changed (prevents overwriting the value in case a request has updated it in the meantime) + && $visitEcommerceStatus != $goalBuyer) { + return $visitEcommerceStatus; + } + + return false; + } + + static public function getVisitEcommerceStatus($status) + { + $id = array_search($status, self::$visitEcommerceStatus); + if ($id === false) { + throw new \Exception("Invalid 'visitEcommerceStatus' segment value $status"); + } + return $id; + } + + /** + * @ignore + */ + static public function getVisitEcommerceStatusFromId($id) + { + if (!isset(self::$visitEcommerceStatus[$id])) { + throw new \Exception("Unexpected ECommerce status value "); + } + return self::$visitEcommerceStatus[$id]; + } + +} \ No newline at end of file diff --git a/plugins/CoreHome/Columns/VisitGoalConverted.php b/plugins/CoreHome/Columns/VisitGoalConverted.php new file mode 100644 index 00000000000..0e4fc72caa6 --- /dev/null +++ b/plugins/CoreHome/Columns/VisitGoalConverted.php @@ -0,0 +1,57 @@ +setSegment('visitConverted'); + $segment->setName('General_VisitConvertedGoal'); + $segment->setAcceptedValues('0, 1'); + $this->addSegment($segment); + } + + public function getName() + { + return ''; + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + return 0; + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onConvertedVisit(Request $request, Visitor $visitor, $action) + { + return 1; + } +} \ No newline at end of file diff --git a/plugins/CoreHome/Columns/VisitLastActionTime.php b/plugins/CoreHome/Columns/VisitLastActionTime.php index 5c45cb31a55..9bf59906870 100644 --- a/plugins/CoreHome/Columns/VisitLastActionTime.php +++ b/plugins/CoreHome/Columns/VisitLastActionTime.php @@ -12,6 +12,7 @@ use Piwik\Tracker\Action; use Piwik\Tracker\Request; use Piwik\Tracker; +use Piwik\Tracker\Visitor; class VisitLastActionTime extends VisitDimension { @@ -19,9 +20,8 @@ class VisitLastActionTime extends VisitDimension // we do not install or define column definition here as we need to create this column when installing as there is // an index on it. Currently we do not define the index here... although we could overwrite the install() method // and add column 'visit_last_action_time' and add index. Problem is there is also an index - // INDEX(idsite, config_id, visit_last_action_time) and we maybe not be sure whether config_id already exists at - // installing point (in case config_id is installed via dimension as well we do not know which column will be added - // first). + // INDEX(idsite, config_id, visit_last_action_time) and we maybe not be sure whether idsite already exists at + // installing point (we do not know whether idsite column will be added first). public function getName() { @@ -30,24 +30,24 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { return Tracker::getDatetimeFromTimestamp($request->getCurrentTimestamp()); } /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onExistingVisit(Request $request, $visit, $action) + public function onExistingVisit(Request $request, Visitor $visitor, $action) { - return $this->onNewVisit($request, $visit, $action); + return $this->onNewVisit($request, $visitor, $action); } } \ No newline at end of file diff --git a/plugins/CoreHome/Columns/VisitTotalTime.php b/plugins/CoreHome/Columns/VisitTotalTime.php new file mode 100644 index 00000000000..02e7a6c5470 --- /dev/null +++ b/plugins/CoreHome/Columns/VisitTotalTime.php @@ -0,0 +1,120 @@ +setSegment('visitDuration'); + $segment->setName('General_ColumnVisitDuration'); + $segment->setType(Segment::TYPE_METRIC); + $this->addSegment($segment); + } + + public function getName() + { + return ''; + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $totalTime = Config::getInstance()->Tracker['default_time_one_page_visit']; + $totalTime = $this->cleanupVisitTotalTime($totalTime); + + return $totalTime; + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) + { + $firstActionTime = $visitor->getVisitorColumn('visit_first_action_time'); + + $totalTime = 1 + $request->getCurrentTimestamp() - $firstActionTime; + $totalTime = $this->cleanupVisitTotalTime($totalTime); + + $this->isExistingVisit = true; + + return $totalTime; + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onConvertedVisit(Request $request, Visitor $visitor, $action) + { + if (!$this->isExistingVisit) { + return false; + } + + $goalManager = new GoalManager($request); + + $totalTime = $visitor->getVisitorColumn('visit_total_time'); + + // If a pageview and goal conversion in the same second, with previously a goal conversion recorded + // the request would not "update" the row since all values are the same as previous + // therefore the request below throws exception, instead we make sure the UPDATE will affect the row + $totalTime = $totalTime + $goalManager->idGoal; + // +2 to offset idgoal=-1 and idgoal=0 + $totalTime = $totalTime + 2; + + return $this->cleanupVisitTotalTime($totalTime); + } + + public function getRequiredVisitFields() + { + return array('visit_first_action_time'); + } + + private function cleanupVisitTotalTime($t) + { + $t = (int)$t; + + if ($t < 0) { + $t = 0; + } + + $smallintMysqlLimit = 65534; + + if ($t > $smallintMysqlLimit) { + $t = $smallintMysqlLimit; + } + + return $t; + } + +} \ No newline at end of file diff --git a/plugins/CoreHome/Columns/VisitorDaysSinceFirst.php b/plugins/CoreHome/Columns/VisitorDaysSinceFirst.php index c418e6e7649..04791dcf81e 100644 --- a/plugins/CoreHome/Columns/VisitorDaysSinceFirst.php +++ b/plugins/CoreHome/Columns/VisitorDaysSinceFirst.php @@ -12,6 +12,7 @@ use Piwik\Plugins\CoreHome\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class VisitorDaysSinceFirst extends VisitDimension { @@ -34,11 +35,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { return $request->getDaysSinceFirstVisit(); } diff --git a/plugins/CoreHome/Columns/VisitorDaysSinceOrder.php b/plugins/CoreHome/Columns/VisitorDaysSinceOrder.php index 5597a426f77..d4007bc58a2 100644 --- a/plugins/CoreHome/Columns/VisitorDaysSinceOrder.php +++ b/plugins/CoreHome/Columns/VisitorDaysSinceOrder.php @@ -9,14 +9,26 @@ namespace Piwik\Plugins\CoreHome\Columns; use Piwik\Plugin\VisitDimension; +use Piwik\Plugins\CoreHome\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class VisitorDaysSinceOrder extends VisitDimension { protected $fieldName = 'visitor_days_since_order'; protected $fieldType = 'SMALLINT(5) UNSIGNED NOT NULL'; + protected function init() + { + $segment = new Segment(); + $segment->setSegment('daysSinceLastEcommerceOrder'); + $segment->setName('General_DaysSinceLastEcommerceOrder'); + $segment->setType(Segment::TYPE_METRIC); + + $this->addSegment($segment); + } + public function getName() { return ''; @@ -24,11 +36,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { $daysSinceLastOrder = $request->getDaysSinceLastOrder(); diff --git a/plugins/CoreHome/Columns/VisitorReturning.php b/plugins/CoreHome/Columns/VisitorReturning.php new file mode 100644 index 00000000000..bfd3c476335 --- /dev/null +++ b/plugins/CoreHome/Columns/VisitorReturning.php @@ -0,0 +1,72 @@ +setSegment('visitorType'); + $segment->setName('General_VisitType'); + $segment->setAcceptedValues($acceptedValues); + $segment->setSqlFilterValue(function ($type) { + return $type == "new" ? 0 : ($type == "returning" ? 1 : 2); + }); + + $this->addSegment($segment); + } + + public function getName() + { + return ''; + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $visitCount = $request->getVisitCount(); + $daysSinceLastVisit = $request->getDaysSinceLastVisit(); + + $daysSinceLastOrder = $request->getDaysSinceLastOrder(); + $isReturningCustomer = ($daysSinceLastOrder !== false); + + if ($isReturningCustomer) { + return self::IS_RETURNING_CUSTOMER; + } + + if ($visitCount > 1 || $visitor->isVisitorKnown() || $daysSinceLastVisit > 0) { + return self::IS_RETURNING; + } + + return self::IS_NEW; + } +} \ No newline at end of file diff --git a/plugins/CoreHome/Columns/VisitsCount.php b/plugins/CoreHome/Columns/VisitsCount.php index 6b900eefef7..6fb53c6ff0c 100644 --- a/plugins/CoreHome/Columns/VisitsCount.php +++ b/plugins/CoreHome/Columns/VisitsCount.php @@ -12,6 +12,7 @@ use Piwik\Plugins\CoreHome\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class VisitsCount extends VisitDimension { @@ -34,11 +35,11 @@ protected function init() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { return $request->getVisitCount(); } diff --git a/plugins/CustomVariables/Columns/CustomVariablename.php b/plugins/CustomVariables/Columns/CustomVariablename.php index 31fa5c58d26..bf7474af9aa 100644 --- a/plugins/CustomVariables/Columns/CustomVariablename.php +++ b/plugins/CustomVariables/Columns/CustomVariablename.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class CustomVariablename extends VisitDimension +class CustomVariableName extends VisitDimension { public function getName() { diff --git a/plugins/CustomVariables/Columns/CustomVariablevalue.php b/plugins/CustomVariables/Columns/CustomVariablevalue.php index 71ca2219f28..7b7f2ef3159 100644 --- a/plugins/CustomVariables/Columns/CustomVariablevalue.php +++ b/plugins/CustomVariables/Columns/CustomVariablevalue.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class CustomVariablevalue extends VisitDimension +class CustomVariableValue extends VisitDimension { public function getName() { diff --git a/plugins/CustomVariables/Reports/GetCustomVariables.php b/plugins/CustomVariables/Reports/GetCustomVariables.php index 930e28adc33..deac87c0a4f 100644 --- a/plugins/CustomVariables/Reports/GetCustomVariables.php +++ b/plugins/CustomVariables/Reports/GetCustomVariables.php @@ -10,14 +10,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\CustomVariables\Columns\CustomVariablename; +use Piwik\Plugins\CustomVariables\Columns\CustomVariableName; class GetCustomVariables extends Base { protected function init() { parent::init(); - $this->dimension = new CustomVariablename(); + $this->dimension = new CustomVariableName(); $this->name = Piwik::translate('CustomVariables_CustomVariables'); $this->documentation = Piwik::translate('CustomVariables_CustomVariablesReportDocumentation', array('
', '', '')); diff --git a/plugins/CustomVariables/Reports/GetCustomVariablesValuesFromNameId.php b/plugins/CustomVariables/Reports/GetCustomVariablesValuesFromNameId.php index 1c173270ebc..cee1bf1f885 100644 --- a/plugins/CustomVariables/Reports/GetCustomVariablesValuesFromNameId.php +++ b/plugins/CustomVariables/Reports/GetCustomVariablesValuesFromNameId.php @@ -10,14 +10,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\CustomVariables\Columns\CustomVariablevalue; +use Piwik\Plugins\CustomVariables\Columns\CustomVariableValue; class GetCustomVariablesValuesFromNameId extends Base { protected function init() { parent::init(); - $this->dimension = new CustomVariablevalue(); + $this->dimension = new CustomVariableValue(); $this->name = Piwik::translate('CustomVariables_CustomVariables'); $this->documentation = Piwik::translate('CustomVariables_CustomVariablesReportDocumentation', array('
', '', '')); diff --git a/plugins/DevicesDetection/Columns/BrowserName.php b/plugins/DevicesDetection/Columns/BrowserName.php index 7545dd2d0bf..f9d6cc552ed 100644 --- a/plugins/DevicesDetection/Columns/BrowserName.php +++ b/plugins/DevicesDetection/Columns/BrowserName.php @@ -10,6 +10,8 @@ use Piwik\Piwik; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class BrowserName extends Base { @@ -20,7 +22,13 @@ public function getName() return Piwik::translate('UserSettings_BrowserFamilies'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); diff --git a/plugins/DevicesDetection/Columns/BrowserVersion.php b/plugins/DevicesDetection/Columns/BrowserVersion.php index c9c557a2a00..ecceac37721 100644 --- a/plugins/DevicesDetection/Columns/BrowserVersion.php +++ b/plugins/DevicesDetection/Columns/BrowserVersion.php @@ -10,6 +10,8 @@ use Piwik\Piwik; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class BrowserVersion extends Base { @@ -20,7 +22,13 @@ public function getName() return Piwik::translate('DevicesDetection_BrowserVersions'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); diff --git a/plugins/DevicesDetection/Columns/DeviceBrand.php b/plugins/DevicesDetection/Columns/DeviceBrand.php index 5a37a53718c..dddaa681850 100644 --- a/plugins/DevicesDetection/Columns/DeviceBrand.php +++ b/plugins/DevicesDetection/Columns/DeviceBrand.php @@ -10,6 +10,8 @@ use Piwik\Piwik; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class DeviceBrand extends Base { @@ -21,7 +23,13 @@ public function getName() return Piwik::translate('DevicesDetection_DeviceBrand'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); diff --git a/plugins/DevicesDetection/Columns/DeviceModel.php b/plugins/DevicesDetection/Columns/DeviceModel.php index a340503af35..078ddb3b1ab 100644 --- a/plugins/DevicesDetection/Columns/DeviceModel.php +++ b/plugins/DevicesDetection/Columns/DeviceModel.php @@ -10,6 +10,8 @@ use Piwik\Piwik; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class DeviceModel extends Base { @@ -21,7 +23,13 @@ public function getName() return Piwik::translate('DevicesDetection_DeviceModel'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); diff --git a/plugins/DevicesDetection/Columns/DeviceType.php b/plugins/DevicesDetection/Columns/DeviceType.php index 5d8d892a27b..00c242c381b 100644 --- a/plugins/DevicesDetection/Columns/DeviceType.php +++ b/plugins/DevicesDetection/Columns/DeviceType.php @@ -13,6 +13,8 @@ use Piwik\Tracker\Request; use DeviceDetector; use Exception; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class DeviceType extends Base { @@ -27,7 +29,7 @@ protected function init() $segment->setCategory('General_Visit'); $segment->setSegment('deviceType'); $segment->setName('DevicesDetection_DeviceType'); - $segment->setAcceptValues($deviceTypeList); + $segment->setAcceptedValues($deviceTypeList); $segment->setSqlFilter(function ($type) use ($deviceTypeList) { $index = array_search(strtolower(trim(urldecode($type))), DeviceDetector::$deviceTypes); if ($index === false) { @@ -44,7 +46,13 @@ public function getName() return Piwik::translate('DevicesDetection_DeviceType'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); diff --git a/plugins/DevicesDetection/Columns/Os.php b/plugins/DevicesDetection/Columns/Os.php index 089b0741a0b..4c2f3bcc65b 100644 --- a/plugins/DevicesDetection/Columns/Os.php +++ b/plugins/DevicesDetection/Columns/Os.php @@ -10,6 +10,8 @@ use Piwik\Piwik; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class Os extends Base { @@ -20,7 +22,13 @@ public function getName() return Piwik::translate('DevicesDetection_OperatingSystemFamilies'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); diff --git a/plugins/DevicesDetection/Columns/OsVersion.php b/plugins/DevicesDetection/Columns/OsVersion.php index 088ca585726..c92c89ff427 100644 --- a/plugins/DevicesDetection/Columns/OsVersion.php +++ b/plugins/DevicesDetection/Columns/OsVersion.php @@ -10,6 +10,8 @@ use Piwik\Piwik; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class OsVersion extends Base { @@ -21,7 +23,13 @@ public function getName() return Piwik::translate('DevicesDetection_OperatingSystemVersions'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); diff --git a/plugins/DevicesDetection/Reports/Base.php b/plugins/DevicesDetection/Reports/Base.php index 9a178bb62c4..75222221b96 100644 --- a/plugins/DevicesDetection/Reports/Base.php +++ b/plugins/DevicesDetection/Reports/Base.php @@ -16,20 +16,4 @@ protected function init() { $this->category = 'DevicesDetection_DevicesDetection'; } - - protected function getOsRelatedReports() - { - return array( - 'DevicesDetection.getOsFamilies' => Piwik::translate('DevicesDetection_OperatingSystemFamilies'), - 'DevicesDetection.getOsVersions' => Piwik::translate('DevicesDetection_OperatingSystemVersions') - ); - } - - protected function getBrowserRelatedReports() - { - return array( - 'DevicesDetection.getBrowserFamilies' => Piwik::translate('UserSettings_BrowserFamilies'), - 'DevicesDetection.getBrowserVersions' => Piwik::translate('DevicesDetection_BrowserVersions') - ); - } } diff --git a/plugins/DevicesDetection/Reports/GetBrowserFamilies.php b/plugins/DevicesDetection/Reports/GetBrowserFamilies.php index 1543b5a472e..b997f585117 100644 --- a/plugins/DevicesDetection/Reports/GetBrowserFamilies.php +++ b/plugins/DevicesDetection/Reports/GetBrowserFamilies.php @@ -10,7 +10,6 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\DevicesDetection\Columns\Browserfamilies; use Piwik\Plugins\DevicesDetection\Columns\BrowserName; class GetBrowserFamilies extends Base @@ -31,7 +30,12 @@ public function configureView(ViewDataTable $view) $view->config->show_search = false; $view->config->show_exclude_low_population = false; $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelBrowserFamily")); - $view->config->addRelatedReports($this->getBrowserRelatedReports()); } + public function getRelatedReports() + { + return array( + new GetBrowserVersions() + ); + } } diff --git a/plugins/DevicesDetection/Reports/GetBrowserVersions.php b/plugins/DevicesDetection/Reports/GetBrowserVersions.php index cf1a00d3c60..12089da7071 100644 --- a/plugins/DevicesDetection/Reports/GetBrowserVersions.php +++ b/plugins/DevicesDetection/Reports/GetBrowserVersions.php @@ -29,7 +29,12 @@ public function configureView(ViewDataTable $view) $view->config->show_search = false; $view->config->show_exclude_low_population = false; $view->config->addTranslation('label', Piwik::translate("UserSettings_ColumnBrowserVersion")); - $view->config->addRelatedReports($this->getBrowserRelatedReports()); } + public function getRelatedReports() + { + return array( + new GetBrowserFamilies() + ); + } } diff --git a/plugins/DevicesDetection/Reports/GetOsFamilies.php b/plugins/DevicesDetection/Reports/GetOsFamilies.php index 7ca9af3aa67..e78b666b2a0 100644 --- a/plugins/DevicesDetection/Reports/GetOsFamilies.php +++ b/plugins/DevicesDetection/Reports/GetOsFamilies.php @@ -10,7 +10,6 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\DevicesDetection\Columns\OperatingSystemfamilies; use Piwik\Plugins\DevicesDetection\Columns\Os; class GetOsFamilies extends Base @@ -31,7 +30,13 @@ public function configureView(ViewDataTable $view) $view->config->show_search = false; $view->config->show_exclude_low_population = false; $view->config->addTranslation('label', Piwik::translate("UserSettings_OperatingSystemFamily")); - $view->config->addRelatedReports($this->getOsRelatedReports()); + } + + public function getRelatedReports() + { + return array( + new GetOsVersions() + ); } } diff --git a/plugins/DevicesDetection/Reports/GetOsVersions.php b/plugins/DevicesDetection/Reports/GetOsVersions.php index 05f70b0770a..6dd5cc0ef1a 100644 --- a/plugins/DevicesDetection/Reports/GetOsVersions.php +++ b/plugins/DevicesDetection/Reports/GetOsVersions.php @@ -30,7 +30,12 @@ public function configureView(ViewDataTable $view) $view->config->show_search = false; $view->config->show_exclude_low_population = false; $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelSystemVersion")); - $view->config->addRelatedReports($this->getOsRelatedReports()); } + public function getRelatedReports() + { + return array( + new GetOsFamilies() + ); + } } diff --git a/plugins/Events/Columns/TotalEvents.php b/plugins/Events/Columns/TotalEvents.php index 3d6ac9f33b6..d94717ea411 100644 --- a/plugins/Events/Columns/TotalEvents.php +++ b/plugins/Events/Columns/TotalEvents.php @@ -13,6 +13,7 @@ use Piwik\Plugin\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class TotalEvents extends VisitDimension { @@ -24,7 +25,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('events'); $segment->setName('Events_TotalEvents'); - $segment->setAcceptValues('To select all visits who triggered an Event, use: &segment=events>0'); + $segment->setAcceptedValues('To select all visits who triggered an Event, use: &segment=events>0'); $segment->setCategory('General_Visit'); $segment->setType(Segment::TYPE_METRIC); $this->addSegment($segment); @@ -37,11 +38,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { if ($this->isEventAction($action)) { return 1; @@ -52,11 +53,11 @@ public function onNewVisit(Request $request, $visit, $action) /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action * @return int */ - public function onExistingVisit(Request $request, $visit, $action) + public function onExistingVisit(Request $request, Visitor $visitor, $action) { if ($this->isEventAction($action)) { return 'visit_total_events + 1'; diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index 8a1cd63d162..6d6ffbc7f39 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -12,6 +12,7 @@ use Piwik\Common; use Piwik\Db; use Piwik\Piwik; +use Piwik\Plugin\Report; use Piwik\Plugin\ViewDataTable; use Piwik\Site; use Piwik\Tracker\GoalManager; @@ -387,6 +388,17 @@ static private function getAllReportsWithGoalMetrics() { $reportsWithGoals = array(); + foreach (Report::getAllReports() as $report) { + if ($report->hasGoalMetrics()) { + $reportsWithGoals[] = array( + 'category' => $report->getCategory(), + 'name' => $report->getName(), + 'module' => $report->getModule(), + 'action' => $report->getAction(), + ); + } + } + /** * Triggered when gathering all reports that contain Goal metrics. The list of reports * will be displayed on the left column of the bottom of every _Goals_ page. @@ -414,6 +426,7 @@ static private function getAllReportsWithGoalMetrics() * - **name**: The report's translated name. * - **module**: The plugin the report is in, eg, `'UserCountry'`. * - **action**: The API method of the report, eg, `'getCountry'`. + * @ignore */ Piwik::postEvent('Goals.getReportsWithGoalMetrics', array(&$reportsWithGoals)); diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php index c52f8dc0f3a..b0adb4a08d0 100644 --- a/plugins/Live/Visitor.php +++ b/plugins/Live/Visitor.php @@ -16,6 +16,7 @@ use Piwik\IP; use Piwik\Piwik; use Piwik\Plugins\API\API as APIMetadata; +use Piwik\Plugins\CoreHome\Columns\VisitGoalBuyer; use Piwik\Plugins\CustomVariables\CustomVariables; use Piwik\Plugins\Referrers\API as APIReferrers; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; @@ -589,7 +590,7 @@ function getVisitEcommerceStatusIcon() function getVisitEcommerceStatus() { - return APIMetadata::getVisitEcommerceStatusFromId($this->details['visit_goal_buyer']); + return VisitGoalBuyer::getVisitEcommerceStatusFromId($this->details['visit_goal_buyer']); } function getVisitorGoalConvertedIcon() diff --git a/plugins/Provider/Columns/Provider.php b/plugins/Provider/Columns/Provider.php index ae07639dade..93792b1d469 100644 --- a/plugins/Provider/Columns/Provider.php +++ b/plugins/Provider/Columns/Provider.php @@ -8,9 +8,16 @@ */ namespace Piwik\Plugins\Provider\Columns; +use Piwik\Common; +use Piwik\IP; use Piwik\Piwik; use Piwik\Plugin\VisitDimension; use Piwik\Plugin\Segment; +use Piwik\Tracker\Action; +use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig; +use Piwik\Plugins\Provider\Provider as ProviderPlugin; class Provider extends VisitDimension { @@ -22,10 +29,64 @@ protected function init() $segment->setSegment('provider'); $segment->setCategory('Visit Location'); $segment->setName('Provider_ColumnProvider'); - $segment->setAcceptValues('comcast.net, proxad.net, etc.'); + $segment->setAcceptedValues('comcast.net, proxad.net, etc.'); $this->addSegment($segment); } + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + // if provider info has already been set, abort + $locationValue = $visitor->getVisitorColumn('location_provider'); + if (!empty($locationValue)) { + return false; + } + + $ip = $visitor->getVisitorColumn('location_ip'); + + $privacyConfig = new PrivacyManagerConfig(); + if (!$privacyConfig->useAnonymizedIpForVisitEnrichment) { + $ip = $request->getIp(); + } + + $ip = IP::N2P($ip); + + // In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking + if (substr($ip, -2, 2) == '.0') { + Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup..."); + return false; + } + + $hostname = $this->getHost($ip); + $hostnameExtension = ProviderPlugin::getCleanHostname($hostname); + + // add the provider value in the table log_visit + $locationProvider = substr($hostnameExtension, 0, 100); + + return $locationProvider; + } + + public function getRequiredVisitFields() + { + return array('location_ip'); + } + + /** + * Returns the hostname given the IP address string + * + * @param string $ip IP Address + * @return string hostname (or human-readable IP address) + */ + private function getHost($ip) + { + return trim(strtolower(@IP::getHostByAddr($ip))); + } + public function getName() { return Piwik::translate('Provider_ColumnProvider'); diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php index 75c7d8686d3..b0d70e0a161 100644 --- a/plugins/Provider/Provider.php +++ b/plugins/Provider/Provider.php @@ -13,25 +13,10 @@ use Piwik\Common; use Piwik\Db; use Piwik\FrontController; -use Piwik\IP; use Piwik\Piwik; -use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig; -/** - * - */ class Provider extends \Piwik\Plugin { - /** - * @see Piwik\Plugin::getListHooksRegistered - */ - public function getListHooksRegistered() - { - return array( - 'Tracker.newVisitorInformation' => 'enrichVisitWithProviderInfo', - ); - } - public function install() { // add column hostname / hostname ext in the visit table @@ -59,40 +44,12 @@ public function postLoad() Piwik::addAction('Template.footerUserCountry', array('Piwik\Plugins\Provider\Provider', 'footerUserCountry')); } - /** - * Logs the provider in the log_visit table - */ - public function enrichVisitWithProviderInfo(&$visitorInfo, \Piwik\Tracker\Request $request) + static public function footerUserCountry(&$out) { - // if provider info has already been set, abort - if (!empty($visitorInfo['location_provider'])) { - return; - } - - $privacyConfig = new PrivacyManagerConfig(); - $ip = IP::N2P($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp()); - - // In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking - if (substr($ip, -2, 2) == '.0') { - Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup..."); - return; - } - - $hostname = $this->getHost($ip); - $hostnameExtension = $this->getCleanHostname($hostname); - - // add the provider value in the table log_visit - $visitorInfo['location_provider'] = $hostnameExtension; - $visitorInfo['location_provider'] = substr($visitorInfo['location_provider'], 0, 100); - - // improve the country using the provider extension if valid - $hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.')); - if ($hostnameDomain == 'uk') { - $hostnameDomain = 'gb'; - } - if (array_key_exists($hostnameDomain, Common::getCountriesList())) { - $visitorInfo['location_country'] = $hostnameDomain; - } + $out = '
+

' . Piwik::translate('Provider_WidgetProviders') . '

'; + $out .= FrontController::getInstance()->fetchDispatch('Provider', 'getProvider'); + $out .= '
'; } /** @@ -103,7 +60,7 @@ public function enrichVisitWithProviderInfo(&$visitorInfo, \Piwik\Tracker\Reques * * @return string */ - private function getCleanHostname($hostname) + public static function getCleanHostname($hostname) { $extToExclude = array( 'com', 'net', 'org', 'co' @@ -119,19 +76,19 @@ private function getCleanHostname($hostname) /** * Triggered when prettifying a hostname string. - * - * This event can be used to customize the way a hostname is displayed in the + * + * This event can be used to customize the way a hostname is displayed in the * Providers report. * * **Example** - * + * * public function getCleanHostname(&$cleanHostname, $hostname) * { * if ('fvae.VARG.ceaga.site.co.jp' == $hostname) { * $cleanHostname = 'site.co.jp'; * } * } - * + * * @param string &$cleanHostname The hostname string to display. Set by the event * handler. * @param string $hostname The full hostname. @@ -153,23 +110,4 @@ private function getCleanHostname($hostname) } } - /** - * Returns the hostname given the IP address string - * - * @param string $ip IP Address - * @return string hostname (or human-readable IP address) - */ - private function getHost($ip) - { - return trim(strtolower(@IP::getHostByAddr($ip))); - } - - static public function footerUserCountry(&$out) - { - $out = '
-

' . Piwik::translate('Provider_WidgetProviders') . '

'; - $out .= FrontController::getInstance()->fetchDispatch('Provider', 'getProvider'); - $out .= '
'; - } - } diff --git a/plugins/Referrers/Columns/Keyword.php b/plugins/Referrers/Columns/Keyword.php index 9cdfabcaf17..31e495e96e2 100644 --- a/plugins/Referrers/Columns/Keyword.php +++ b/plugins/Referrers/Columns/Keyword.php @@ -11,6 +11,8 @@ use Piwik\Piwik; use Piwik\Plugins\Referrers\Segment; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class Keyword extends Base { @@ -22,7 +24,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('referrerKeyword'); $segment->setName('General_ColumnKeyword'); - $segment->setAcceptValues('Encoded%20Keyword, keyword'); + $segment->setAcceptedValues('Encoded%20Keyword, keyword'); $this->addSegment($segment); } @@ -31,7 +33,13 @@ public function getName() return Piwik::translate('General_ColumnKeyword'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); @@ -42,6 +50,6 @@ public function onNewVisit(Request $request, $visit) return substr($information['referer_keyword'], 0, 255); } - return $information['referer_keyword'];; + return $information['referer_keyword']; } } diff --git a/plugins/Referrers/Columns/ReferrerName.php b/plugins/Referrers/Columns/ReferrerName.php index 7952229d34b..38e1ec9bb18 100644 --- a/plugins/Referrers/Columns/ReferrerName.php +++ b/plugins/Referrers/Columns/ReferrerName.php @@ -10,6 +10,8 @@ use Piwik\Plugins\Referrers\Segment; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class ReferrerName extends Base { @@ -21,7 +23,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('referrerName'); $segment->setName('Referrers_ReferrerName'); - $segment->setAcceptValues('twitter.com, www.facebook.com, Bing, Google, Yahoo, CampaignName'); + $segment->setAcceptedValues('twitter.com, www.facebook.com, Bing, Google, Yahoo, CampaignName'); $this->addSegment($segment); } @@ -30,7 +32,13 @@ public function getName() return ''; } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); diff --git a/plugins/Referrers/Columns/ReferrerType.php b/plugins/Referrers/Columns/ReferrerType.php index 2709f609dea..93df8e406d4 100644 --- a/plugins/Referrers/Columns/ReferrerType.php +++ b/plugins/Referrers/Columns/ReferrerType.php @@ -11,6 +11,8 @@ use Piwik\Piwik; use Piwik\Plugins\Referrers\Segment; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class ReferrerType extends Base { @@ -23,7 +25,7 @@ protected function init() $segment->setSegment('referrerType'); $segment->setName('Referrers_Type'); $segment->setSqlFilterValue('Piwik\Plugins\Referrers\getReferrerTypeFromShortName'); - $segment->setAcceptValues('direct, search, website, campaign'); + $segment->setAcceptedValues('direct, search, website, campaign'); $this->addSegment($segment); } @@ -32,7 +34,13 @@ public function getName() return Piwik::translate('Referrers_Type'); } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); diff --git a/plugins/Referrers/Columns/ReferrerUrl.php b/plugins/Referrers/Columns/ReferrerUrl.php index 849a9529757..b2e50ecfe3a 100644 --- a/plugins/Referrers/Columns/ReferrerUrl.php +++ b/plugins/Referrers/Columns/ReferrerUrl.php @@ -10,6 +10,8 @@ use Piwik\Plugins\Referrers\Segment; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; class ReferrerUrl extends Base { @@ -21,7 +23,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('referrerUrl'); $segment->setName('Live_Referrer_URL'); - $segment->setAcceptValues('http%3A%2F%2Fwww.example.org%2Freferer-page.htm'); + $segment->setAcceptedValues('http%3A%2F%2Fwww.example.org%2Freferer-page.htm'); $this->addSegment($segment); } @@ -30,7 +32,13 @@ public function getName() return ''; } - public function onNewVisit(Request $request, $visit) + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); diff --git a/plugins/Referrers/Columns/Socialnetwork.php b/plugins/Referrers/Columns/Socialnetwork.php index 9fa210819d8..e5c0f22b3d7 100644 --- a/plugins/Referrers/Columns/Socialnetwork.php +++ b/plugins/Referrers/Columns/Socialnetwork.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class Socialnetwork extends VisitDimension +class SocialNetwork extends VisitDimension { public function getName() { diff --git a/plugins/Referrers/Referrers.php b/plugins/Referrers/Referrers.php index dcc9133da69..3097cfceb20 100644 --- a/plugins/Referrers/Referrers.php +++ b/plugins/Referrers/Referrers.php @@ -27,11 +27,9 @@ class Referrers extends \Piwik\Plugin */ public function getListHooksRegistered() { - $hooks = array( - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + return array( 'Insights.addReportToOverview' => 'addReportToInsightsOverview' ); - return $hooks; } public function addReportToInsightsOverview(&$reports) @@ -42,40 +40,6 @@ public function addReportToInsightsOverview(&$reports) $reports['Referrers_getSearchEngines'] = array(); } - /** - * Adds Goal dimensions, so that the dimensions are displayed in the UI Goal Overview page - */ - public function getReportsWithGoalMetrics(&$dimensions) - { - $dimensions = array_merge($dimensions, array( - array('category' => Piwik::translate('Referrers_Referrers'), - 'name' => Piwik::translate('Referrers_Type'), - 'module' => 'Referrers', - 'action' => 'getReferrerType', - ), - array('category' => Piwik::translate('Referrers_Referrers'), - 'name' => Piwik::translate('Referrers_Keywords'), - 'module' => 'Referrers', - 'action' => 'getKeywords', - ), - array('category' => Piwik::translate('Referrers_Referrers'), - 'name' => Piwik::translate('Referrers_SearchEngines'), - 'module' => 'Referrers', - 'action' => 'getSearchEngines', - ), - array('category' => Piwik::translate('Referrers_Referrers'), - 'name' => Piwik::translate('Referrers_Websites'), - 'module' => 'Referrers', - 'action' => 'getWebsites', - ), - array('category' => Piwik::translate('Referrers_Referrers'), - 'name' => Piwik::translate('Referrers_Campaigns'), - 'module' => 'Referrers', - 'action' => 'getCampaigns', - ), - )); - } - /** * DataTable filter callback that returns the HTML prefix for a label in the * 'getAll' report based on the row's referrer type. diff --git a/plugins/Referrers/Reports/GetCampaigns.php b/plugins/Referrers/Reports/GetCampaigns.php index 8db3b0a2fae..53282f6c384 100644 --- a/plugins/Referrers/Reports/GetCampaigns.php +++ b/plugins/Referrers/Reports/GetCampaigns.php @@ -22,6 +22,7 @@ protected function init() $this->documentation = Piwik::translate('Referrers_CampaignsReportDocumentation', array('
', '', '')); $this->actionToLoadSubTables = 'getKeywordsFromCampaignId'; + $this->hasGoalMetrics = true; $this->order = 9; $this->widgetTitle = 'Referrers_Campaigns'; } diff --git a/plugins/Referrers/Reports/GetKeywords.php b/plugins/Referrers/Reports/GetKeywords.php index 9d0680aa140..b6949f9f01c 100644 --- a/plugins/Referrers/Reports/GetKeywords.php +++ b/plugins/Referrers/Reports/GetKeywords.php @@ -22,6 +22,7 @@ protected function init() $this->name = Piwik::translate('Referrers_Keywords'); $this->documentation = Piwik::translate('Referrers_KeywordsReportDocumentation', '
'); $this->actionToLoadSubTables = 'getSearchEnginesFromKeywordId'; + $this->hasGoalMetrics = true; $this->order = 3; $this->widgetTitle = 'Referrers_WidgetKeywords'; } diff --git a/plugins/Referrers/Reports/GetReferrerType.php b/plugins/Referrers/Reports/GetReferrerType.php index e856a61367c..b53734b0386 100644 --- a/plugins/Referrers/Reports/GetReferrerType.php +++ b/plugins/Referrers/Reports/GetReferrerType.php @@ -30,6 +30,7 @@ protected function init() . '' . Piwik::translate('Referrers_Campaigns') . ': ' . Piwik::translate('Referrers_CampaignsDocumentation', array('
', '"' . Piwik::translate('Referrers_Campaigns') . '"')); $this->constantRowsCount = true; + $this->hasGoalMetrics = true; $this->order = 1; $this->widgetTitle = 'General_Overview'; } diff --git a/plugins/Referrers/Reports/GetSearchEngines.php b/plugins/Referrers/Reports/GetSearchEngines.php index fc89e14de06..a85e0d1977d 100644 --- a/plugins/Referrers/Reports/GetSearchEngines.php +++ b/plugins/Referrers/Reports/GetSearchEngines.php @@ -22,6 +22,7 @@ protected function init() $this->name = Piwik::translate('Referrers_SearchEngines'); $this->documentation = Piwik::translate('Referrers_SearchEnginesReportDocumentation', '
'); $this->actionToLoadSubTables = 'getKeywordsFromSearchEngineId'; + $this->hasGoalMetrics = true; $this->order = 7; $this->widgetTitle = 'Referrers_SearchEngines'; } diff --git a/plugins/Referrers/Reports/GetSocials.php b/plugins/Referrers/Reports/GetSocials.php index fd3475f226f..e59ae446903 100644 --- a/plugins/Referrers/Reports/GetSocials.php +++ b/plugins/Referrers/Reports/GetSocials.php @@ -13,14 +13,14 @@ use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; -use Piwik\Plugins\Referrers\Columns\Socialnetwork; +use Piwik\Plugins\Referrers\Columns\SocialNetwork; class GetSocials extends Base { protected function init() { parent::init(); - $this->dimension = new Socialnetwork(); + $this->dimension = new SocialNetwork(); $this->name = Piwik::translate('Referrers_Socials'); $this->documentation = Piwik::translate('Referrers_WebsitesReportDocumentation', '
'); $this->actionToLoadSubTables = 'getUrlsForSocial'; diff --git a/plugins/Referrers/Reports/GetWebsites.php b/plugins/Referrers/Reports/GetWebsites.php index 7f6b507e10c..0c0a5212c68 100644 --- a/plugins/Referrers/Reports/GetWebsites.php +++ b/plugins/Referrers/Reports/GetWebsites.php @@ -22,6 +22,7 @@ protected function init() $this->name = Piwik::translate('CorePluginsAdmin_Websites'); $this->documentation = Piwik::translate('Referrers_WebsitesReportDocumentation', '
'); $this->actionToLoadSubTables = 'getUrlsFromWebsiteId'; + $this->hasGoalMetrics = true; $this->order = 5; $this->widgetTitle = 'Referrers_WidgetExternalWebsites'; } diff --git a/plugins/UserCountry/Columns/Base.php b/plugins/UserCountry/Columns/Base.php new file mode 100644 index 00000000000..48d5fc897ad --- /dev/null +++ b/plugins/UserCountry/Columns/Base.php @@ -0,0 +1,164 @@ +urlParamToOverride)) { + return false; + } + + if (!$request->isAuthenticated()) { + return false; + } + + $value = Common::getRequestVar($urlParamToOverride, false, 'string', $request->getParams()); + if (!empty($value)) { + return $value; + } + + return false; + } + + public function getRequiredVisitFields() + { + return array('location_ip', 'location_browser_lang'); + } + + protected function getLocationDetail($userInfo, $locationKey) + { + $location = $this->getCachedLocation($userInfo); + + if (!empty($location[$locationKey])) { + return $location[$locationKey]; + } + + return false; + } + + protected function getUserInfo(Request $request, Visitor $visitor) + { + $ipAddress = $this->getIpAddress($visitor->getVisitorColumn('location_ip'), $request); + $language = $visitor->getVisitorColumn('location_browser_lang'); + $userInfo = array('lang' => $language, 'ip' => $ipAddress); + + return $userInfo; + } + + protected function getCachedLocation($userInfo) + { + require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; + + $key = md5(implode(',', $userInfo)); + + if (array_key_exists($key, $this->cachedLocations)) { + return $this->cachedLocations[$key]; + } + + $provider = $this->getProvider(); + $location = $this->getLocation($provider, $userInfo); + + if (empty($location)) { + $providerId = $provider->getId(); + Common::printDebug("GEO: couldn't find a location with Geo Module '$providerId'"); + + if (!$this->isDefaultProvider($provider)) { + Common::printDebug("Using default provider as fallback..."); + $provider = $this->getDefaultProvider(); + $location = $this->getLocation($provider, $userInfo); + } + } + + if (empty($location['country_code'])) { // sanity check + $location['country_code'] = Visit::UNKNOWN_CODE; + } + + $this->cachedLocations[$key] = $location; + + return $location; + } + + private function getIpAddress($anonymizedIp, \Piwik\Tracker\Request $request) + { + $privacyConfig = new PrivacyManagerConfig(); + + $ip = $request->getIp(); + + if ($privacyConfig->useAnonymizedIpForVisitEnrichment) { + $ip = $anonymizedIp; + } + + $ipAddress = IP::N2P($ip); + + return $ipAddress; + } + + /** + * @param \Piwik\Plugins\UserCountry\LocationProvider $provider + * @param array $userInfo + * @return array|null + */ + private function getLocation($provider, $userInfo) + { + $location = $provider->getLocation($userInfo); + $providerId = $provider->getId(); + $ipAddress = $userInfo['ip']; + + if ($location === false) { + return false; + } + + Common::printDebug("GEO: Found IP $ipAddress location (provider '" . $providerId . "'): " . var_export($location, true)); + + return $location; + } + + private function getDefaultProvider() + { + $id = DefaultProvider::ID; + $provider = LocationProvider::getProviderById($id); + + return $provider; + } + + private function isDefaultProvider($provider) + { + return !empty($provider) && DefaultProvider::ID == $provider->getId(); + } + + private function getProvider() + { + $id = Common::getCurrentLocationProviderId(); + $provider = LocationProvider::getProviderById($id); + + if ($provider === false) { + $provider = $this->getDefaultProvider(); + Common::printDebug("GEO: no current location provider sent, falling back to default '$id' one."); + } + + return $provider; + } + +} \ No newline at end of file diff --git a/plugins/UserCountry/Columns/City.php b/plugins/UserCountry/Columns/City.php index 400c313db4c..929dae92f21 100644 --- a/plugins/UserCountry/Columns/City.php +++ b/plugins/UserCountry/Columns/City.php @@ -9,19 +9,23 @@ namespace Piwik\Plugins\UserCountry\Columns; use Piwik\Piwik; -use Piwik\Plugin\VisitDimension; +use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; use Piwik\Plugins\UserCountry\Segment; -class City extends VisitDimension +class City extends Base { protected $fieldName = 'location_city'; + protected $fieldType = 'varchar(255) DEFAULT NULL'; protected function init() { $segment = new Segment(); $segment->setSegment('city'); $segment->setName('UserCountry_City'); - $segment->setAcceptValues('Sydney, Sao Paolo, Rome, etc.'); + $segment->setAcceptedValues('Sydney, Sao Paolo, Rome, etc.'); $this->addSegment($segment); } @@ -29,4 +33,34 @@ public function getName() { return Piwik::translate('UserCountry_City'); } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $value = $this->getUrlOverrideValueIfAllowed('city', $request); + + if ($value !== false) { + return $value; + } + + $userInfo = $this->getUserInfo($request, $visitor); + + return $this->getLocationDetail($userInfo, LocationProvider::CITY_NAME_KEY); + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) + { + return $this->getUrlOverrideValueIfAllowed('city', $request); + } } \ No newline at end of file diff --git a/plugins/UserCountry/Columns/Country.php b/plugins/UserCountry/Columns/Country.php index a84106ecd67..a9feced9f69 100644 --- a/plugins/UserCountry/Columns/Country.php +++ b/plugins/UserCountry/Columns/Country.php @@ -8,27 +8,35 @@ */ namespace Piwik\Plugins\UserCountry\Columns; +use Piwik\Common; +use Piwik\IP; use Piwik\Piwik; -use Piwik\Plugin\VisitDimension; +use Piwik\Plugins\Provider\Provider; +use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Plugins\UserCountry\Segment; +use Piwik\Tracker\Visit; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; +use Piwik\Tracker\Request; -class Country extends VisitDimension +class Country extends Base { protected $fieldName = 'location_country'; + protected $fieldType = 'CHAR(3) NOT NULL'; protected function init() { $segment = new Segment(); $segment->setSegment('countryCode'); $segment->setName('UserCountry_Country'); - $segment->setAcceptValues('de, us, fr, in, es, etc.'); + $segment->setAcceptedValues('de, us, fr, in, es, etc.'); $this->addSegment($segment); $segment = new Segment(); $segment->setSegment('continentCode'); $segment->setName('UserCountry_Continent'); $segment->setSqlFilter('Piwik\Plugins\UserCountry\UserCountry::getCountriesForContinent'); - $segment->setAcceptValues('eur, asi, amc, amn, ams, afr, ant, oce'); + $segment->setAcceptedValues('eur, asi, amc, amn, ams, afr, ant, oce'); $this->addSegment($segment); } @@ -36,4 +44,74 @@ public function getName() { return Piwik::translate('UserCountry_Country'); } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $value = $this->getUrlOverrideValueIfAllowed('country', $request); + + if ($value !== false) { + return $value; + } + + $userInfo = $this->getUserInfo($request, $visitor); + $country = $this->getLocationDetail($userInfo, LocationProvider::COUNTRY_CODE_KEY); + + if (!empty($country) && $country != Visit::UNKNOWN_CODE) { + + return strtolower($country); + } + + $country = $this->getCountryUsingProviderExtensionIfValid($userInfo['ip']); + + if (!empty($country)) { + return $country; + } + + return Visit::UNKNOWN_CODE; + } + + private function getCountryUsingProviderExtensionIfValid($ipAddress) + { + $hostname = $this->getHost($ipAddress); + $hostnameExtension = Provider::getCleanHostname($hostname); + + $hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.')); + if ($hostnameDomain == 'uk') { + $hostnameDomain = 'gb'; + } + + if (array_key_exists($hostnameDomain, Common::getCountriesList())) { + return $hostnameDomain; + } + + return false; + } + + /** + * Returns the hostname given the IP address string + * + * @param string $ip IP Address + * @return string hostname (or human-readable IP address) + */ + private function getHost($ip) + { + return trim(strtolower(@IP::getHostByAddr($ip))); + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) + { + return $this->getUrlOverrideValueIfAllowed('country', $request); + } } \ No newline at end of file diff --git a/plugins/UserCountry/Columns/Latitude.php b/plugins/UserCountry/Columns/Latitude.php index 64713c70f16..afadffee9db 100644 --- a/plugins/UserCountry/Columns/Latitude.php +++ b/plugins/UserCountry/Columns/Latitude.php @@ -9,19 +9,23 @@ namespace Piwik\Plugins\UserCountry\Columns; use Piwik\Piwik; -use Piwik\Plugin\VisitDimension; +use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Plugins\UserCountry\Segment; +use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; -class Latitude extends VisitDimension +class Latitude extends Base { protected $fieldName = 'location_latitude'; + protected $fieldType = 'float(10, 6) DEFAULT NULL'; protected function init() { $segment = new Segment(); $segment->setSegment('latitude'); $segment->setName('UserCountry_Latitude'); - $segment->setAcceptValues('-33.578, 40.830, etc.
You can select visitors within a lat/long range using &segment=lat>X;lat<Y;long>M;long<N.'); + $segment->setAcceptedValues('-33.578, 40.830, etc.
You can select visitors within a lat/long range using &segment=lat>X;lat<Y;long>M;long<N.'); $this->addSegment($segment); } @@ -29,4 +33,34 @@ public function getName() { return Piwik::translate('UserCountry_Latitude'); } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $value = $this->getUrlOverrideValueIfAllowed('lat', $request); + + if ($value !== false) { + return $value; + } + + $userInfo = $this->getUserInfo($request, $visitor); + + return $this->getLocationDetail($userInfo, LocationProvider::LATITUDE_KEY); + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) + { + return $this->getUrlOverrideValueIfAllowed('lat', $request); + } } \ No newline at end of file diff --git a/plugins/UserCountry/Columns/Longitude.php b/plugins/UserCountry/Columns/Longitude.php index bf4f63869bc..d5971321c3f 100644 --- a/plugins/UserCountry/Columns/Longitude.php +++ b/plugins/UserCountry/Columns/Longitude.php @@ -9,19 +9,23 @@ namespace Piwik\Plugins\UserCountry\Columns; use Piwik\Piwik; -use Piwik\Plugin\VisitDimension; +use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Plugins\UserCountry\Segment; +use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; -class Longitude extends VisitDimension +class Longitude extends Base { protected $fieldName = 'location_longitude'; + protected $fieldType = 'float(10, 6) DEFAULT NULL'; protected function init() { $segment = new Segment(); $segment->setSegment('longitude'); $segment->setName('UserCountry_Longitude'); - $segment->setAcceptValues('-70.664, 14.326, etc.'); + $segment->setAcceptedValues('-70.664, 14.326, etc.'); $this->addSegment($segment); } @@ -29,4 +33,34 @@ public function getName() { return Piwik::translate('UserCountry_Latitude'); } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $value = $this->getUrlOverrideValueIfAllowed('long', $request); + + if ($value !== false) { + return $value; + } + + $userInfo = $this->getUserInfo($request, $visitor); + + return $this->getLocationDetail($userInfo, LocationProvider::LONGITUDE_KEY); + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) + { + return $this->getUrlOverrideValueIfAllowed('long', $request); + } } \ No newline at end of file diff --git a/plugins/UserCountry/Columns/Provider.php b/plugins/UserCountry/Columns/Provider.php new file mode 100644 index 00000000000..8eb7761db1a --- /dev/null +++ b/plugins/UserCountry/Columns/Provider.php @@ -0,0 +1,61 @@ +isPluginInstalled('Provider')) { + return false; + } + + $userInfo = $this->getUserInfo($request, $visitor); + + $isp = $this->getLocationDetail($userInfo, LocationProvider::ISP_KEY); + $org = $this->getLocationDetail($userInfo, LocationProvider::ORG_KEY); + + // if the location has provider/organization info, set it + if (!empty($isp)) { + $providerValue = $isp; + + // if the org is set and not the same as the isp, add it to the provider value + if (!empty($org) && $org != $providerValue) { + $providerValue .= ' - ' . $org; + } + + return $providerValue; + } + + if (!empty($org)) { + return $org; + } + + return false; + } +} \ No newline at end of file diff --git a/plugins/UserCountry/Columns/Region.php b/plugins/UserCountry/Columns/Region.php index fd8ffc19a2f..6010a7de5f6 100644 --- a/plugins/UserCountry/Columns/Region.php +++ b/plugins/UserCountry/Columns/Region.php @@ -9,19 +9,23 @@ namespace Piwik\Plugins\UserCountry\Columns; use Piwik\Piwik; -use Piwik\Plugin\VisitDimension; +use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Plugins\UserCountry\Segment; +use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; +use Piwik\Tracker\Action; -class Region extends VisitDimension +class Region extends Base { protected $fieldName = 'location_region'; + protected $fieldType = 'char(2) DEFAULT NULL'; protected function init() { $segment = new Segment(); $segment->setSegment('regionCode'); $segment->setName('UserCountry_Region'); - $segment->setAcceptValues('01 02, OR, P8, etc.
eg. region=A1;country=fr'); + $segment->setAcceptedValues('01 02, OR, P8, etc.
eg. region=A1;country=fr'); $this->addSegment($segment); } @@ -29,4 +33,34 @@ public function getName() { return Piwik::translate('UserCountry_Region'); } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + $value = $this->getUrlOverrideValueIfAllowed('region', $request); + + if ($value !== false) { + return $value; + } + + $userInfo = $this->getUserInfo($request, $visitor); + + return $this->getLocationDetail($userInfo, LocationProvider::REGION_CODE_KEY); + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return int + */ + public function onExistingVisit(Request $request, Visitor $visitor, $action) + { + return $this->getUrlOverrideValueIfAllowed('region', $request); + } } \ No newline at end of file diff --git a/plugins/UserCountry/LocationProvider.php b/plugins/UserCountry/LocationProvider.php index 20754a20b52..bd656984246 100755 --- a/plugins/UserCountry/LocationProvider.php +++ b/plugins/UserCountry/LocationProvider.php @@ -307,14 +307,21 @@ public static function setCurrentProvider($providerId) public static function getProviderById($providerId) { foreach (self::getAvailableProviders() as $provider) { - $info = $provider->getInfo(); - if ($info['id'] == $providerId) { + if ($provider->getId() == $providerId) { return $provider; } } + return false; } + public function getId() + { + $info = $this->getInfo(); + + return $info['id']; + } + /** * Tries to fill in any missing information in a location result. * diff --git a/plugins/UserCountry/Reports/GetCity.php b/plugins/UserCountry/Reports/GetCity.php index 51f9a3baa35..7619e427f64 100644 --- a/plugins/UserCountry/Reports/GetCity.php +++ b/plugins/UserCountry/Reports/GetCity.php @@ -17,10 +17,11 @@ class GetCity extends Base protected function init() { parent::init(); - $this->dimension = new City(); - $this->name = Piwik::translate('UserCountry_City'); - $this->documentation = Piwik::translate('UserCountry_getCityDocumentation') . '
' . $this->getGeoIPReportDocSuffix(); - $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->dimension = new City(); + $this->name = Piwik::translate('UserCountry_City'); + $this->documentation = Piwik::translate('UserCountry_getCityDocumentation') . '
' . $this->getGeoIPReportDocSuffix(); + $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->hasGoalMetrics = true; $this->order = 8; $this->widgetTitle = Piwik::translate('UserCountry_WidgetLocation') . ' (' . Piwik::translate('UserCountry_City') . ')'; diff --git a/plugins/UserCountry/Reports/GetContinent.php b/plugins/UserCountry/Reports/GetContinent.php index 129c7405552..1640dd9cc3d 100644 --- a/plugins/UserCountry/Reports/GetContinent.php +++ b/plugins/UserCountry/Reports/GetContinent.php @@ -17,10 +17,11 @@ class GetContinent extends Base protected function init() { parent::init(); - $this->dimension = new Continent(); - $this->name = Piwik::translate('UserCountry_Continent'); - $this->documentation = Piwik::translate('UserCountry_getContinentDocumentation'); - $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->dimension = new Continent(); + $this->name = Piwik::translate('UserCountry_Continent'); + $this->documentation = Piwik::translate('UserCountry_getContinentDocumentation'); + $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->hasGoalMetrics = true; $this->order = 6; $this->widgetTitle = Piwik::translate('UserCountry_WidgetLocation') . ' (' . Piwik::translate('UserCountry_Continent') . ')'; diff --git a/plugins/UserCountry/Reports/GetCountry.php b/plugins/UserCountry/Reports/GetCountry.php index 0043c6a33cc..4e1a0475f47 100644 --- a/plugins/UserCountry/Reports/GetCountry.php +++ b/plugins/UserCountry/Reports/GetCountry.php @@ -18,10 +18,11 @@ class GetCountry extends Base protected function init() { parent::init(); - $this->dimension = new Country(); - $this->name = Piwik::translate('UserCountry_Country'); - $this->documentation = Piwik::translate('UserCountry_getCountryDocumentation'); - $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->dimension = new Country(); + $this->name = Piwik::translate('UserCountry_Country'); + $this->documentation = Piwik::translate('UserCountry_getCountryDocumentation'); + $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->hasGoalMetrics = true; $this->order = 5; $this->widgetTitle = Piwik::translate('UserCountry_WidgetLocation') . ' (' . Piwik::translate('UserCountry_Country') . ')'; diff --git a/plugins/UserCountry/Reports/GetRegion.php b/plugins/UserCountry/Reports/GetRegion.php index 071f6ce326d..dd038ce63f7 100644 --- a/plugins/UserCountry/Reports/GetRegion.php +++ b/plugins/UserCountry/Reports/GetRegion.php @@ -17,10 +17,11 @@ class GetRegion extends Base protected function init() { parent::init(); - $this->dimension = new Region(); - $this->name = Piwik::translate('UserCountry_Region'); - $this->documentation = Piwik::translate('UserCountry_getRegionDocumentation') . '
' . $this->getGeoIPReportDocSuffix(); - $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->dimension = new Region(); + $this->name = Piwik::translate('UserCountry_Region'); + $this->documentation = Piwik::translate('UserCountry_getRegionDocumentation') . '
' . $this->getGeoIPReportDocSuffix(); + $this->metrics = array('nb_visits', 'nb_uniq_visitors', 'nb_actions'); + $this->hasGoalMetrics = true; $this->order = 7; $this->widgetTitle = Piwik::translate('UserCountry_WidgetLocation') . ' (' . Piwik::translate('UserCountry_Region') . ')'; diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index 8b75e579e1f..e8d9bdf9794 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -11,13 +11,9 @@ use Piwik\ArchiveProcessor; use Piwik\Common; use Piwik\Config; -use Piwik\IP; use Piwik\Piwik; -use Piwik\Plugin\Manager; -use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; use Piwik\Plugins\UserCountry\LocationProvider; -use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider; use Piwik\Url; /** @@ -35,16 +31,13 @@ class UserCountry extends \Piwik\Plugin */ public function getListHooksRegistered() { - $hooks = array( - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + return array( 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'AssetManager.getJavaScriptFiles' => 'getJsFiles', - 'Tracker.newVisitorInformation' => 'enrichVisitWithLocation', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral', 'Insights.addReportToOverview' => 'addReportToInsightsOverview' ); - return $hooks; } public function addReportToInsightsOverview(&$reports) @@ -67,121 +60,6 @@ public function getJsFiles(&$jsFiles) $jsFiles[] = "plugins/UserCountry/javascripts/userCountry.js"; } - public function enrichVisitWithLocation(&$visitorInfo, \Piwik\Tracker\Request $request) - { - require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; - - $privacyConfig = new PrivacyManagerConfig(); - - $ipAddress = IP::N2P($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp()); - $userInfo = array( - 'lang' => $visitorInfo['location_browser_lang'], - 'ip' => $ipAddress - ); - - $id = Common::getCurrentLocationProviderId(); - $provider = LocationProvider::getProviderById($id); - if ($provider === false) { - $id = DefaultProvider::ID; - $provider = LocationProvider::getProviderById($id); - Common::printDebug("GEO: no current location provider sent, falling back to default '$id' one."); - } - - $location = $provider->getLocation($userInfo); - - // if we can't find a location, use default provider - if ($location === false) { - $defaultId = DefaultProvider::ID; - $provider = LocationProvider::getProviderById($defaultId); - $location = $provider->getLocation($userInfo); - Common::printDebug("GEO: couldn't find a location with Geo Module '$id', using Default '$defaultId' provider as fallback..."); - $id = $defaultId; - } - Common::printDebug("GEO: Found IP $ipAddress location (provider '" . $id . "'): " . var_export($location, true)); - - if (empty($location['country_code'])) { // sanity check - $location['country_code'] = \Piwik\Tracker\Visit::UNKNOWN_CODE; - } - - // add optional location components - $this->updateVisitInfoWithLocation($visitorInfo, $location); - } - - /** - * Sets visitor info array with location info. - * - * @param array $visitorInfo - * @param array $location See LocationProvider::getLocation for more info. - */ - private function updateVisitInfoWithLocation(&$visitorInfo, $location) - { - static $logVisitToLowerLocationMapping = array( - 'location_country' => LocationProvider::COUNTRY_CODE_KEY, - ); - - static $logVisitToLocationMapping = array( - 'location_region' => LocationProvider::REGION_CODE_KEY, - 'location_city' => LocationProvider::CITY_NAME_KEY, - 'location_latitude' => LocationProvider::LATITUDE_KEY, - 'location_longitude' => LocationProvider::LONGITUDE_KEY, - ); - - foreach ($logVisitToLowerLocationMapping as $column => $locationKey) { - if (!empty($location[$locationKey])) { - $visitorInfo[$column] = strtolower($location[$locationKey]); - } - } - - foreach ($logVisitToLocationMapping as $column => $locationKey) { - if (!empty($location[$locationKey])) { - $visitorInfo[$column] = $location[$locationKey]; - } - } - - // if the location has provider/organization info, set it - if (!empty($location[LocationProvider::ISP_KEY])) { - $providerValue = $location[LocationProvider::ISP_KEY]; - - // if the org is set and not the same as the isp, add it to the provider value - if (!empty($location[LocationProvider::ORG_KEY]) - && $location[LocationProvider::ORG_KEY] != $providerValue - ) { - $providerValue .= ' - ' . $location[LocationProvider::ORG_KEY]; - } - } else if (!empty($location[LocationProvider::ORG_KEY])) { - $providerValue = $location[LocationProvider::ORG_KEY]; - } - - if (isset($providerValue) - && Manager::getInstance()->isPluginInstalled('Provider')) { - $visitorInfo['location_provider'] = $providerValue; - } - } - - public function getReportsWithGoalMetrics(&$dimensions) - { - $dimensions = array_merge($dimensions, array( - array('category' => Piwik::translate('General_Visit'), - 'name' => Piwik::translate('UserCountry_Country'), - 'module' => 'UserCountry', - 'action' => 'getCountry', - ), - array('category' => Piwik::translate('General_Visit'), - 'name' => Piwik::translate('UserCountry_Continent'), - 'module' => 'UserCountry', - 'action' => 'getContinent', - ), - array('category' => Piwik::translate('General_Visit'), - 'name' => Piwik::translate('UserCountry_Region'), - 'module' => 'UserCountry', - 'action' => 'getRegion'), - array('category' => Piwik::translate('General_Visit'), - 'name' => Piwik::translate('UserCountry_City'), - 'module' => 'UserCountry', - 'action' => 'getCity'), - )); - } - /** * Returns a list of country codes for a given continent code. * diff --git a/plugins/UserSettings/Columns/Browser.php b/plugins/UserSettings/Columns/Browser.php index 80055afd918..e3534b426eb 100644 --- a/plugins/UserSettings/Columns/Browser.php +++ b/plugins/UserSettings/Columns/Browser.php @@ -22,7 +22,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('browserCode'); $segment->setName('UserSettings_ColumnBrowser'); - $segment->setAcceptValues('FF, IE, CH, SF, OP, etc.'); + $segment->setAcceptedValues('FF, IE, CH, SF, OP, etc.'); $this->addSegment($segment); } diff --git a/plugins/UserSettings/Columns/Browserfamily.php b/plugins/UserSettings/Columns/Browserfamily.php index cdd40f67bf6..227a31dd4f7 100644 --- a/plugins/UserSettings/Columns/Browserfamily.php +++ b/plugins/UserSettings/Columns/Browserfamily.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class Browserfamily extends VisitDimension +class BrowserFamily extends VisitDimension { public function getName() { diff --git a/plugins/UserSettings/Columns/Browserversion.php b/plugins/UserSettings/Columns/Browserversion.php index e93e7f19f4c..4decf254506 100644 --- a/plugins/UserSettings/Columns/Browserversion.php +++ b/plugins/UserSettings/Columns/Browserversion.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugins\UserSettings\Segment; -class Browserversion extends \Piwik\Plugins\DevicesDetection\Columns\BrowserVersion +class BrowserVersion extends \Piwik\Plugins\DevicesDetection\Columns\BrowserVersion { protected $fieldName = 'config_browser_version'; protected $fieldType = 'VARCHAR(20) NOT NULL'; @@ -21,7 +21,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('browserVersion'); $segment->setName('UserSettings_ColumnBrowserVersion'); - $segment->setAcceptValues('1.0, 8.0, etc.'); + $segment->setAcceptedValues('1.0, 8.0, etc.'); $this->addSegment($segment); } diff --git a/plugins/UserSettings/Columns/Language.php b/plugins/UserSettings/Columns/Language.php index 03459756398..a9997e806a4 100644 --- a/plugins/UserSettings/Columns/Language.php +++ b/plugins/UserSettings/Columns/Language.php @@ -12,6 +12,7 @@ use Piwik\Plugin\VisitDimension; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class Language extends VisitDimension { @@ -25,11 +26,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { return substr($request->getBrowserLanguage(), 0, 20); } diff --git a/plugins/UserSettings/Columns/Operatingsystem.php b/plugins/UserSettings/Columns/Operatingsystem.php index b65a0cbc9f3..0a6d6770cfc 100644 --- a/plugins/UserSettings/Columns/Operatingsystem.php +++ b/plugins/UserSettings/Columns/Operatingsystem.php @@ -22,7 +22,7 @@ protected function init() $segment = new Segment(); $segment->setSegment('operatingSystemCode'); $segment->setName('UserSettings_ColumnOperatingSystem'); - $segment->setAcceptValues('WXP, WI7, MAC, LIN, AND, IPD, etc.'); + $segment->setAcceptedValues('WXP, WI7, MAC, LIN, AND, IPD, etc.'); $this->addSegment($segment); } diff --git a/plugins/UserSettings/Columns/Operatingsystemfamily.php b/plugins/UserSettings/Columns/Operatingsystemfamily.php index 1b1f7411f92..b4c2d6640d4 100644 --- a/plugins/UserSettings/Columns/Operatingsystemfamily.php +++ b/plugins/UserSettings/Columns/Operatingsystemfamily.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class Operatingsystemfamily extends VisitDimension +class OperatingsystemFamily extends VisitDimension { public function getName() { diff --git a/plugins/UserSettings/Columns/Resolution.php b/plugins/UserSettings/Columns/Resolution.php index 407daf7db42..19bf2a1ee5d 100644 --- a/plugins/UserSettings/Columns/Resolution.php +++ b/plugins/UserSettings/Columns/Resolution.php @@ -13,6 +13,7 @@ use Piwik\Plugins\UserSettings\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class Resolution extends VisitDimension { @@ -24,17 +25,17 @@ protected function init() $segment = new Segment(); $segment->setSegment('resolution'); $segment->setName('UserSettings_ColumnResolution'); - $segment->setAcceptValues('1280x1024, 800x600, etc.'); + $segment->setAcceptedValues('1280x1024, 800x600, etc.'); $this->addSegment($segment); } /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { $resolution = $request->getParam('res'); diff --git a/plugins/UserSettings/Columns/Typeofscreen.php b/plugins/UserSettings/Columns/Typeofscreen.php index 592076f136a..a042d2323d8 100644 --- a/plugins/UserSettings/Columns/Typeofscreen.php +++ b/plugins/UserSettings/Columns/Typeofscreen.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class Typeofscreen extends VisitDimension +class TypeOfScreen extends VisitDimension { public function getName() { diff --git a/plugins/UserSettings/Reports/Base.php b/plugins/UserSettings/Reports/Base.php index 4ed0ea7360b..bfa11a78c39 100644 --- a/plugins/UserSettings/Reports/Base.php +++ b/plugins/UserSettings/Reports/Base.php @@ -8,7 +8,6 @@ */ namespace Piwik\Plugins\UserSettings\Reports; -use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; @@ -30,28 +29,4 @@ protected function getBasicUserSettingsDisplayProperties(ViewDataTable $view) $view->config->max_graph_elements = 5; } } - - protected function getBrowserRelatedReports() - { - return array( - 'UserSettings.getBrowser' => Piwik::translate('UserSettings_Browsers'), - 'UserSettings.getBrowserVersion' => Piwik::translate('UserSettings_ColumnBrowserVersion') - ); - } - - protected function getOsRelatedReports() - { - return array( - 'UserSettings.getOSFamily' => Piwik::translate('UserSettings_OperatingSystemFamily'), - 'UserSettings.getOS' => Piwik::translate('UserSettings_OperatingSystems') - ); - } - - protected function getWideScreenDeviceTypeRelatedReports() - { - return array( - 'UserSettings.getMobileVsDesktop' => Piwik::translate('UserSettings_MobileVsDesktop'), - 'UserSettings.getWideScreen' => Piwik::translate('UserSettings_ColumnTypeOfScreen') - ); - } } diff --git a/plugins/UserSettings/Reports/GetBrowser.php b/plugins/UserSettings/Reports/GetBrowser.php index c9c56ccfe9d..b0a169bf9af 100644 --- a/plugins/UserSettings/Reports/GetBrowser.php +++ b/plugins/UserSettings/Reports/GetBrowser.php @@ -31,11 +31,16 @@ public function configureView(ViewDataTable $view) $view->config->title = Piwik::translate('UserSettings_Browsers'); $view->config->addTranslation('label', $this->dimension->getName()); - $view->config->addRelatedReports($this->getBrowserRelatedReports()); if ($view->isViewDataTableId(Graph::ID)) { $view->config->max_graph_elements = 7; } } + public function getRelatedReports() + { + return array( + new GetBrowserVersion() + ); + } } diff --git a/plugins/UserSettings/Reports/GetBrowserType.php b/plugins/UserSettings/Reports/GetBrowserType.php index 34ab6aab327..063abab7cee 100644 --- a/plugins/UserSettings/Reports/GetBrowserType.php +++ b/plugins/UserSettings/Reports/GetBrowserType.php @@ -11,14 +11,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; -use Piwik\Plugins\UserSettings\Columns\Browserfamily; +use Piwik\Plugins\UserSettings\Columns\BrowserFamily; class GetBrowserType extends Base { protected function init() { parent::init(); - $this->dimension = new Browserfamily(); + $this->dimension = new BrowserFamily(); $this->name = Piwik::translate('UserSettings_WidgetBrowserFamilies'); $this->documentation = Piwik::translate('UserSettings_WidgetBrowserFamiliesDocumentation', '
'); $this->order = 3; diff --git a/plugins/UserSettings/Reports/GetBrowserVersion.php b/plugins/UserSettings/Reports/GetBrowserVersion.php index d04f02f2342..31cb0a74c76 100644 --- a/plugins/UserSettings/Reports/GetBrowserVersion.php +++ b/plugins/UserSettings/Reports/GetBrowserVersion.php @@ -11,14 +11,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; -use Piwik\Plugins\UserSettings\Columns\Browserversion; +use Piwik\Plugins\UserSettings\Columns\BrowserVersion; class GetBrowserVersion extends Base { protected function init() { parent::init(); - $this->dimension = new Browserversion(); + $this->dimension = new BrowserVersion(); $this->name = Piwik::translate('UserSettings_WidgetBrowserVersion'); $this->documentation = ''; // TODO $this->order = 2; @@ -31,11 +31,17 @@ public function configureView(ViewDataTable $view) $view->config->title = Piwik::translate('UserSettings_ColumnBrowserVersion'); $view->config->addTranslation('label', $this->dimension->getName()); - $view->config->addRelatedReports($this->getBrowserRelatedReports()); if ($view->isViewDataTableId(Graph::ID)) { $view->config->max_graph_elements = 7; } } + public function getRelatedReports() + { + return array( + new GetBrowser() + ); + } + } diff --git a/plugins/UserSettings/Reports/GetMobileVsDesktop.php b/plugins/UserSettings/Reports/GetMobileVsDesktop.php index 20e1bcb3351..4eb06d5b264 100644 --- a/plugins/UserSettings/Reports/GetMobileVsDesktop.php +++ b/plugins/UserSettings/Reports/GetMobileVsDesktop.php @@ -31,7 +31,13 @@ public function configureView(ViewDataTable $view) $view->config->title = Piwik::translate('UserSettings_MobileVsDesktop'); $view->config->addTranslation('label', $this->dimension->getName()); - $view->config->addRelatedReports($this->getWideScreenDeviceTypeRelatedReports()); + } + + public function getRelatedReports() + { + return array( + new GetWideScreen() + ); } } diff --git a/plugins/UserSettings/Reports/GetOS.php b/plugins/UserSettings/Reports/GetOS.php index 040e69c4181..d42793630e0 100644 --- a/plugins/UserSettings/Reports/GetOS.php +++ b/plugins/UserSettings/Reports/GetOS.php @@ -30,7 +30,12 @@ public function configureView(ViewDataTable $view) $view->config->title = Piwik::translate('UserSettings_OperatingSystems'); $view->config->addTranslation('label', $this->dimension->getName()); - $view->config->addRelatedReports($this->getOsRelatedReports()); } + public function getRelatedReports() + { + return array( + new GetOSFamily() + ); + } } diff --git a/plugins/UserSettings/Reports/GetOSFamily.php b/plugins/UserSettings/Reports/GetOSFamily.php index cb6451f03b8..c1c112d71c0 100644 --- a/plugins/UserSettings/Reports/GetOSFamily.php +++ b/plugins/UserSettings/Reports/GetOSFamily.php @@ -10,14 +10,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\UserSettings\Columns\Operatingsystemfamily; +use Piwik\Plugins\UserSettings\Columns\OperatingsystemFamily; class GetOSFamily extends Base { protected function init() { parent::init(); - $this->dimension = new Operatingsystemfamily(); + $this->dimension = new OperatingsystemFamily(); $this->name = Piwik::translate('UserSettings_OperatingSystemFamily'); $this->documentation = ''; // TODO $this->order = 8; @@ -30,7 +30,13 @@ public function configureView(ViewDataTable $view) $view->config->title = $this->name; $view->config->addTranslation('label', $this->dimension->getName()); - $view->config->addRelatedReports($this->getOsRelatedReports()); + } + + public function getRelatedReports() + { + return array( + new GetOS() + ); } } diff --git a/plugins/UserSettings/Reports/GetWideScreen.php b/plugins/UserSettings/Reports/GetWideScreen.php index bfadd87a9e2..23b65476131 100644 --- a/plugins/UserSettings/Reports/GetWideScreen.php +++ b/plugins/UserSettings/Reports/GetWideScreen.php @@ -10,14 +10,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\UserSettings\Columns\Typeofscreen; +use Piwik\Plugins\UserSettings\Columns\TypeOfScreen; class GetWideScreen extends Base { protected function init() { parent::init(); - $this->dimension = new Typeofscreen(); + $this->dimension = new TypeOfScreen(); $this->name = Piwik::translate('UserSettings_WidgetWidescreen'); $this->documentation = ''; // TODO $this->order = 5; @@ -33,7 +33,12 @@ public function configureView(ViewDataTable $view) $view->config->show_pagination_control = false; $view->config->show_limit_control = false; $view->config->addTranslation('label', $this->dimension->getName()); - $view->config->addRelatedReports($this->getWideScreenDeviceTypeRelatedReports()); } + public function getRelatedReports() + { + return array( + new GetMobileVsDesktop() + ); + } } diff --git a/plugins/VisitTime/Columns/Dayoftheweek.php b/plugins/VisitTime/Columns/Dayoftheweek.php index 950f3f80a10..99b8f819d50 100644 --- a/plugins/VisitTime/Columns/Dayoftheweek.php +++ b/plugins/VisitTime/Columns/Dayoftheweek.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class Dayoftheweek extends VisitDimension +class DayOfTheWeek extends VisitDimension { public function getName() { diff --git a/plugins/VisitTime/Columns/Localtime.php b/plugins/VisitTime/Columns/Localtime.php index 6f0cc5f7272..ea57eb3e683 100644 --- a/plugins/VisitTime/Columns/Localtime.php +++ b/plugins/VisitTime/Columns/Localtime.php @@ -13,8 +13,9 @@ use Piwik\Plugins\VisitTime\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; -class Localtime extends VisitDimension +class LocalTime extends VisitDimension { protected $fieldName = 'visitor_localtime'; protected $fieldType = 'TIME NOT NULL'; @@ -25,7 +26,7 @@ protected function init() $segment->setSegment('visitLocalHour'); $segment->setName('VisitTime_ColumnLocalTime'); $segment->setSqlSegment('HOUR(log_visit.visitor_localtime)'); - $segment->setAcceptValues('0, 1, 2, 3, ..., 20, 21, 22, 23'); + $segment->setAcceptedValues('0, 1, 2, 3, ..., 20, 21, 22, 23'); $this->addSegment($segment); } @@ -36,11 +37,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { return $request->getLocalTime(); } diff --git a/plugins/VisitTime/Columns/Servertime.php b/plugins/VisitTime/Columns/Servertime.php index 69cf2f54dc8..6e69670d93e 100644 --- a/plugins/VisitTime/Columns/Servertime.php +++ b/plugins/VisitTime/Columns/Servertime.php @@ -12,7 +12,7 @@ use Piwik\Plugin\VisitDimension; use Piwik\Plugins\VisitTime\Segment; -class Servertime extends VisitDimension +class ServerTime extends VisitDimension { protected $fieldName = 'visit_last_action_time'; @@ -22,7 +22,7 @@ protected function init() $segment->setSegment('visitServerHour'); $segment->setName('VisitTime_ColumnServerTime'); $segment->setSqlSegment('HOUR(log_visit.visit_last_action_time)'); - $segment->setAcceptValues('0, 1, 2, 3, ..., 20, 21, 22, 23'); + $segment->setAcceptedValues('0, 1, 2, 3, ..., 20, 21, 22, 23'); $this->addSegment($segment); } diff --git a/plugins/VisitTime/Reports/GetByDayOfWeek.php b/plugins/VisitTime/Reports/GetByDayOfWeek.php index 3905beaac2f..a01d0ed8cec 100644 --- a/plugins/VisitTime/Reports/GetByDayOfWeek.php +++ b/plugins/VisitTime/Reports/GetByDayOfWeek.php @@ -12,7 +12,7 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; -use Piwik\Plugins\VisitTime\Columns\Dayoftheweek; +use Piwik\Plugins\VisitTime\Columns\DayOfTheWeek; use Piwik\Period; use Piwik\Site; @@ -21,7 +21,7 @@ class GetByDayOfWeek extends Base protected function init() { parent::init(); - $this->dimension = new Dayoftheweek(); + $this->dimension = new DayOfTheWeek(); $this->name = Piwik::translate('VisitTime_VisitsByDayOfWeek'); $this->documentation = Piwik::translate('VisitTime_WidgetByDayOfWeekDocumentation'); $this->constantRowsCount = true; diff --git a/plugins/VisitTime/Reports/GetVisitInformationPerLocalTime.php b/plugins/VisitTime/Reports/GetVisitInformationPerLocalTime.php index 330aaaf3aa8..7700cc67d55 100644 --- a/plugins/VisitTime/Reports/GetVisitInformationPerLocalTime.php +++ b/plugins/VisitTime/Reports/GetVisitInformationPerLocalTime.php @@ -12,14 +12,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; -use Piwik\Plugins\VisitTime\Columns\Localtime; +use Piwik\Plugins\VisitTime\Columns\LocalTime; class GetVisitInformationPerLocalTime extends Base { protected function init() { parent::init(); - $this->dimension = new Localtime(); + $this->dimension = new LocalTime(); $this->name = Piwik::translate('VisitTime_WidgetLocalTime'); $this->documentation = Piwik::translate('VisitTime_WidgetLocalTimeDocumentation', array('', '')); $this->constantRowsCount = true; diff --git a/plugins/VisitTime/Reports/GetVisitInformationPerServerTime.php b/plugins/VisitTime/Reports/GetVisitInformationPerServerTime.php index 68fd602aee2..87901a97ac4 100644 --- a/plugins/VisitTime/Reports/GetVisitInformationPerServerTime.php +++ b/plugins/VisitTime/Reports/GetVisitInformationPerServerTime.php @@ -11,17 +11,18 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; -use Piwik\Plugins\VisitTime\Columns\Servertime; +use Piwik\Plugins\VisitTime\Columns\ServerTime; class GetVisitInformationPerServerTime extends Base { protected function init() { parent::init(); - $this->dimension = new Servertime(); + $this->dimension = new ServerTime(); $this->name = Piwik::translate('VisitTime_WidgetServerTime'); $this->documentation = Piwik::translate('VisitTime_WidgetServerTimeDocumentation', array('', '')); $this->constantRowsCount = true; + $this->hasGoalMetrics = true; $this->order = 15; $this->widgetTitle = 'VisitTime_WidgetServerTime'; } diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index 3a4d3b7685d..bbec1792682 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -8,39 +8,7 @@ */ namespace Piwik\Plugins\VisitTime; -use Exception; -use Piwik\ArchiveProcessor; -use Piwik\Common; -use Piwik\Period; -use Piwik\Piwik; -use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; -use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Bar; -use Piwik\Site; - -/** - * - */ +// empty plugin definition, otherwise plugin won't be installed during test run class VisitTime extends \Piwik\Plugin { - /** - * @see Piwik\Plugin::getListHooksRegistered - */ - public function getListHooksRegistered() - { - return array( - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics' - ); - } - - public function getReportsWithGoalMetrics(&$dimensions) - { - $dimensions[] = array('category' => Piwik::translate('VisitTime_ColumnServerTime'), - 'name' => Piwik::translate('VisitTime_ColumnServerTime'), - 'module' => 'VisitTime', - 'action' => 'getVisitInformationPerServerTime', - ); - } - - } diff --git a/plugins/VisitorInterest/Columns/Pagespervisit.php b/plugins/VisitorInterest/Columns/Pagespervisit.php index d16beb449b9..a85b8bf71ef 100644 --- a/plugins/VisitorInterest/Columns/Pagespervisit.php +++ b/plugins/VisitorInterest/Columns/Pagespervisit.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class Pagespervisit extends VisitDimension +class PagesPerVisit extends VisitDimension { public function getName() { diff --git a/plugins/VisitorInterest/Columns/Visitduration.php b/plugins/VisitorInterest/Columns/Visitduration.php index 69553678921..e483bc7c3ab 100644 --- a/plugins/VisitorInterest/Columns/Visitduration.php +++ b/plugins/VisitorInterest/Columns/Visitduration.php @@ -11,7 +11,7 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; -class Visitduration extends VisitDimension +class VisitDuration extends VisitDimension { public function getName() { diff --git a/plugins/VisitorInterest/Columns/Visitsbydayssincelastvisit.php b/plugins/VisitorInterest/Columns/Visitsbydayssincelastvisit.php index 075c6e7aaea..e64515181d2 100644 --- a/plugins/VisitorInterest/Columns/Visitsbydayssincelastvisit.php +++ b/plugins/VisitorInterest/Columns/Visitsbydayssincelastvisit.php @@ -10,14 +10,26 @@ use Piwik\Piwik; use Piwik\Plugin\VisitDimension; +use Piwik\Plugins\CoreHome\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; -class Visitsbydayssincelastvisit extends VisitDimension +class VisitsByDaysSinceLastVisit extends VisitDimension { protected $fieldName = 'visitor_days_since_last'; protected $fieldType = 'SMALLINT(5) UNSIGNED NOT NULL'; + protected function init() + { + $segment = new Segment(); + $segment->setSegment('daysSinceLastVisit'); + $segment->setName('General_DaysSinceLastVisit'); + $segment->setType(Segment::TYPE_METRIC); + + $this->addSegment($segment); + } + public function getName() { return Piwik::translate('VisitorInterest_VisitsByDaysSinceLast'); @@ -25,11 +37,11 @@ public function getName() /** * @param Request $request - * @param array $visit + * @param Visitor $visitor * @param Action|null $action - * @return int + * @return mixed */ - public function onNewVisit(Request $request, $visit, $action) + public function onNewVisit(Request $request, Visitor $visitor, $action) { return $request->getDaysSinceLastVisit(); } diff --git a/plugins/VisitorInterest/Reports/GetNumberOfVisitsByDaysSinceLast.php b/plugins/VisitorInterest/Reports/GetNumberOfVisitsByDaysSinceLast.php index cd5ca482dff..679917fdcca 100644 --- a/plugins/VisitorInterest/Reports/GetNumberOfVisitsByDaysSinceLast.php +++ b/plugins/VisitorInterest/Reports/GetNumberOfVisitsByDaysSinceLast.php @@ -10,14 +10,14 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Plugins\VisitorInterest\Columns\Visitsbydayssincelastvisit; +use Piwik\Plugins\VisitorInterest\Columns\VisitsByDaysSinceLastVisit; class GetNumberOfVisitsByDaysSinceLast extends Base { protected function init() { parent::init(); - $this->dimension = new Visitsbydayssincelastvisit(); + $this->dimension = new VisitsByDaysSinceLastVisit(); $this->name = Piwik::translate('VisitorInterest_VisitsByDaysSinceLast'); $this->documentation = Piwik::translate('VisitorInterest_WidgetVisitsByDaysSinceLastDocumentation'); $this->metrics = array('nb_visits'); diff --git a/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerPage.php b/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerPage.php index c805195e93e..3efc243ccc7 100644 --- a/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerPage.php +++ b/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerPage.php @@ -12,14 +12,14 @@ use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Cloud; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; -use Piwik\Plugins\VisitorInterest\Columns\Pagespervisit; +use Piwik\Plugins\VisitorInterest\Columns\PagesPerVisit; class GetNumberOfVisitsPerPage extends Base { protected function init() { parent::init(); - $this->dimension = new Pagespervisit(); + $this->dimension = new PagesPerVisit(); $this->name = Piwik::translate('VisitorInterest_WidgetPages'); $this->documentation = Piwik::translate('VisitorInterest_WidgetPagesDocumentation') . '
' . Piwik::translate('General_ChangeTagCloudView'); diff --git a/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerVisitDuration.php b/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerVisitDuration.php index 7b79dd92edc..a447ea22fe7 100644 --- a/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerVisitDuration.php +++ b/plugins/VisitorInterest/Reports/GetNumberOfVisitsPerVisitDuration.php @@ -12,14 +12,14 @@ use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Cloud; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; -use Piwik\Plugins\VisitorInterest\Columns\Visitduration; +use Piwik\Plugins\VisitorInterest\Columns\VisitDuration; class GetNumberOfVisitsPerVisitDuration extends Base { protected function init() { parent::init(); - $this->dimension = new Visitduration(); + $this->dimension = new VisitDuration(); $this->name = Piwik::translate('VisitorInterest_WidgetLengths'); $this->documentation = Piwik::translate('VisitorInterest_WidgetLengthsDocumentation') . '
' . Piwik::translate('General_ChangeTagCloudView'); diff --git a/plugins/VisitsSummary/Reports/Get.php b/plugins/VisitsSummary/Reports/Get.php index b3dfe1ff1ac..433eb85ab72 100644 --- a/plugins/VisitsSummary/Reports/Get.php +++ b/plugins/VisitsSummary/Reports/Get.php @@ -34,7 +34,7 @@ protected function init() $this->order = 1; } - protected function getMetrics() + public function getMetrics() { $metrics = parent::getMetrics();