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 = '