diff options
Diffstat (limited to 'plugins/VisitorInterest/Columns')
3 files changed, 91 insertions, 41 deletions
diff --git a/plugins/VisitorInterest/Columns/VisitorDaysSinceLast.php b/plugins/VisitorInterest/Columns/VisitorDaysSinceLast.php new file mode 100644 index 0000000000..e1f886dd8a --- /dev/null +++ b/plugins/VisitorInterest/Columns/VisitorDaysSinceLast.php @@ -0,0 +1,23 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Plugins\VisitorInterest\Columns; + +use Piwik\Plugin\Dimension\VisitDimension; +use Piwik\Plugin\Segment; + +class VisitorDaysSinceLast extends VisitDimension +{ + protected $category = 'General_Visitors'; + protected $type = self::TYPE_NUMBER; + protected $nameSingular = 'General_DaysSinceLastVisit'; + protected $columnName = 'visitor_seconds_since_last'; + protected $sqlSegment = 'FLOOR(log_visit.visitor_seconds_since_last / 86400)'; + protected $segmentName = 'daysSinceLastVisit'; +}
\ No newline at end of file diff --git a/plugins/VisitorInterest/Columns/VisitorSecondsSinceLast.php b/plugins/VisitorInterest/Columns/VisitorSecondsSinceLast.php new file mode 100644 index 0000000000..ffc9787f7a --- /dev/null +++ b/plugins/VisitorInterest/Columns/VisitorSecondsSinceLast.php @@ -0,0 +1,68 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\VisitorInterest\Columns; + +use Piwik\Common; +use Piwik\Date; +use Piwik\Piwik; +use Piwik\Plugin\Dimension\VisitDimension; +use Piwik\Plugin\Segment; +use Piwik\Tracker\Action; +use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; + +class VisitorSecondsSinceLast extends VisitDimension +{ + const COLUMN_TYPE = 'INT(11) UNSIGNED NULL'; + + protected $columnName = 'visitor_seconds_since_last'; + protected $columnType = self::COLUMN_TYPE; + protected $type = self::TYPE_NUMBER; + protected $segmentName = 'secondsSinceLastVisit'; + protected $nameSingular = 'General_SecondsSinceLastVisit'; + + public function getName() + { + return Piwik::translate('General_SecondsSinceLastVisit'); + } + + /** + * @param Request $request + * @param Visitor $visitor + * @param Action|null $action + * @return mixed + */ + public function onNewVisit(Request $request, Visitor $visitor, $action) + { + if (!$visitor->isVisitorKnown()) { + return 0; + } + + $currentTimestamp = $request->getCurrentTimestamp(); + + $previousVisitFirstActionTime = $visitor->getPreviousVisitColumn('visit_first_action_time'); + if (empty($previousVisitFirstActionTime)) { + return 0; + } + + $previousVisitFirstActionTime = Date::factory($previousVisitFirstActionTime)->getTimestamp(); + + if (empty($previousVisitFirstActionTime)) { + Common::printDebug("Found empty visit_first_action_time for last visit of known visitor, this is unexpected."); + return 0; + } + + $secondsSinceLast = $currentTimestamp - $previousVisitFirstActionTime; + if ($secondsSinceLast < 0) { // tracking a visit in the past + return null; + } + + return $secondsSinceLast; + } +}
\ No newline at end of file diff --git a/plugins/VisitorInterest/Columns/VisitsByDaysSinceLastVisit.php b/plugins/VisitorInterest/Columns/VisitsByDaysSinceLastVisit.php deleted file mode 100644 index 89cd4b64b9..0000000000 --- a/plugins/VisitorInterest/Columns/VisitsByDaysSinceLastVisit.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php -/** - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\VisitorInterest\Columns; - -use Piwik\Piwik; -use Piwik\Plugin\Dimension\VisitDimension; -use Piwik\Tracker\Action; -use Piwik\Tracker\Request; -use Piwik\Tracker\Visitor; - -class VisitsByDaysSinceLastVisit extends VisitDimension -{ - protected $columnName = 'visitor_days_since_last'; - protected $columnType = 'SMALLINT(5) UNSIGNED NULL'; - protected $type = self::TYPE_NUMBER; - protected $segmentName = 'daysSinceLastVisit'; - protected $nameSingular = 'General_DaysSinceLastVisit'; - - public function getName() - { - return Piwik::translate('VisitorInterest_VisitsByDaysSinceLast'); - } - - /** - * @param Request $request - * @param Visitor $visitor - * @param Action|null $action - * @return mixed - */ - public function onNewVisit(Request $request, Visitor $visitor, $action) - { - return $request->getDaysSinceLastVisit(); - } - -}
\ No newline at end of file |