diff options
Diffstat (limited to 'plugins/VisitFrequency')
-rw-r--r-- | plugins/VisitFrequency/Controller.php | 63 | ||||
-rw-r--r-- | plugins/VisitFrequency/Menu.php | 19 | ||||
-rw-r--r-- | plugins/VisitFrequency/Reports/Get.php | 90 | ||||
-rw-r--r-- | plugins/VisitFrequency/Widgets.php | 23 | ||||
-rw-r--r-- | plugins/VisitFrequency/lang/en.json | 10 | ||||
-rw-r--r-- | plugins/VisitFrequency/templates/_sparklines.twig | 39 | ||||
-rw-r--r-- | plugins/VisitFrequency/templates/getSparklines.twig | 1 | ||||
-rw-r--r-- | plugins/VisitFrequency/templates/index.twig | 9 |
8 files changed, 109 insertions, 145 deletions
diff --git a/plugins/VisitFrequency/Controller.php b/plugins/VisitFrequency/Controller.php index da3c9e461b..855d1286de 100644 --- a/plugins/VisitFrequency/Controller.php +++ b/plugins/VisitFrequency/Controller.php @@ -8,9 +8,10 @@ */ namespace Piwik\Plugins\VisitFrequency; -use Piwik\API\Request; use Piwik\Common; +use Piwik\FrontController; use Piwik\Piwik; +use Piwik\Plugins\CoreVisualizations\Visualizations\Sparklines; use Piwik\Translation\Translator; use Piwik\View; @@ -28,31 +29,22 @@ class Controller extends \Piwik\Plugin\Controller parent::__construct(); } - public function index() - { - $view = new View('@VisitFrequency/index'); - $this->setGeneralVariablesView($view); - - $view->graphEvolutionVisitFrequency = $this->getEvolutionGraph(array(), array('nb_visits_returning')); - $this->setSparklinesAndNumbers($view); - - return $view->render(); - } - + /** + * @deprecated used to be a widgetized URL. There to not break widget URLs + */ public function getSparklines() { - $view = new View('@VisitFrequency/getSparklines'); - $this->setSparklinesAndNumbers($view); - return $view->render(); + $_GET['forceView'] = '1'; + $_GET['viewDataTable'] = Sparklines::ID; + + return FrontController::getInstance()->fetchDispatch('VisitFrequency', 'get'); } - public function getEvolutionGraph(array $columns = array(), array $defaultColumns = array()) + public function getEvolutionGraph() { - if (empty($columns)) { - $columns = Common::getRequestVar('columns', false); - if (false !== $columns) { - $columns = Piwik::getArrayFromApiParameter($columns); - } + $columns = Common::getRequestVar('columns', false); + if (false !== $columns) { + $columns = Piwik::getArrayFromApiParameter($columns); } $documentation = $this->translator->translate('VisitFrequency_ReturningVisitsDocumentation') . '<br />' @@ -90,35 +82,10 @@ class Controller extends \Piwik\Plugin\Controller $view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns, $selectableColumns, $documentation); - if (empty($view->config->columns_to_display) && !empty($defaultColumns)) { - $view->config->columns_to_display = $defaultColumns; + if (empty($view->config->columns_to_display)) { + $view->config->columns_to_display = array('nb_visits_returning'); } return $this->renderView($view); } - - protected function setSparklinesAndNumbers($view) - { - $view->urlSparklineNbVisitsReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_visits_returning'))); - $view->urlSparklineNbActionsReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_actions_returning'))); - $view->urlSparklineActionsPerVisitReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_actions_per_visit_returning'))); - $view->urlSparklineAvgVisitDurationReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('avg_time_on_site_returning'))); - $view->urlSparklineBounceRateReturning = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('bounce_rate_returning'))); - - $dataTableFrequency = $this->getSummary(); - $dataRow = $dataTableFrequency->getFirstRow(); - $nbVisitsReturning = $dataRow->getColumn('nb_visits_returning'); - $view->nbVisitsReturning = $nbVisitsReturning; - $view->nbActionsReturning = $dataRow->getColumn('nb_actions_returning'); - $view->nbActionsPerVisitReturning = $dataRow->getColumn('nb_actions_per_visit_returning'); - $view->avgVisitDurationReturning = $dataRow->getColumn('avg_time_on_site_returning'); - $view->bounceRateReturning = $dataRow->getColumn('bounce_rate_returning'); - } - - protected function getSummary() - { - $requestString = "method=VisitFrequency.get&format=original"; - $request = new Request($requestString); - return $request->process(); - } } diff --git a/plugins/VisitFrequency/Menu.php b/plugins/VisitFrequency/Menu.php deleted file mode 100644 index e858bd2f76..0000000000 --- a/plugins/VisitFrequency/Menu.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\VisitFrequency; - -use Piwik\Menu\MenuReporting; - -class Menu extends \Piwik\Plugin\Menu -{ - public function configureReportingMenu(MenuReporting $menu) - { - $menu->addVisitorsItem('VisitFrequency_SubmenuFrequency', $this->urlForAction('index'), $order = 55); - } -} diff --git a/plugins/VisitFrequency/Reports/Get.php b/plugins/VisitFrequency/Reports/Get.php index eb4c7ddfbe..9904c9ddd4 100644 --- a/plugins/VisitFrequency/Reports/Get.php +++ b/plugins/VisitFrequency/Reports/Get.php @@ -8,18 +8,25 @@ */ namespace Piwik\Plugins\VisitFrequency\Reports; +use Piwik\DataTable; +use Piwik\NumberFormatter; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreHome\Columns\Metrics\ActionsPerVisit; use Piwik\Plugins\CoreHome\Columns\Metrics\AverageTimeOnSite; use Piwik\Plugins\CoreHome\Columns\Metrics\BounceRate; +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution; +use Piwik\Plugins\CoreVisualizations\Visualizations\Sparklines; use Piwik\Plugins\VisitFrequency\Columns\Metrics\ReturningMetric; +use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; class Get extends \Piwik\Plugin\Report { protected function init() { parent::init(); - $this->category = 'General_Visitors'; + $this->categoryId = 'General_Visitors'; $this->name = Piwik::translate('VisitFrequency_ColumnReturningVisits'); $this->documentation = ''; // TODO $this->processedMetrics = array( @@ -35,5 +42,86 @@ class Get extends \Piwik\Plugin\Report 'max_actions_returning' ); $this->order = 40; + $this->subcategoryId = 'VisitorInterest_Engagement'; } + + public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory) + { + $widgetsList->addWidgetConfig( + $factory->createWidget() + ->setName('VisitFrequency_WidgetGraphReturning') + ->forceViewDataTable(Evolution::ID) + ->setAction('getEvolutionGraph') + ->setOrder(1) + ); + + $widgetsList->addWidgetConfig( + $factory->createWidget() + ->forceViewDataTable(Sparklines::ID) + ->setName('VisitFrequency_WidgetOverview') + ->setOrder(2) + ); + } + + public function configureView(ViewDataTable $view) + { + if ($view->isViewDataTableId(Sparklines::ID)) { + $view->requestConfig->apiMethodToRequestDataTable = 'VisitFrequency.get'; + $this->addSparklineColumns($view); + $view->config->addTranslations($this->getSparklineTranslations()); + + $numberFormatter = NumberFormatter::getInstance(); + $view->config->filters[] = function (DataTable $table) use ($numberFormatter) { + $firstRow = $table->getFirstRow(); + if ($firstRow) { + $value = $firstRow->getColumn('nb_visits_returning'); + if (false !== $value) { + $firstRow->setColumn('nb_visits_returning', $numberFormatter->formatNumber($value)); + } + + $value = $firstRow->getColumn('nb_actions_returning'); + if (false !== $value) { + $firstRow->setColumn('nb_actions_returning', $numberFormatter->formatNumber($value)); + } + + $value = $firstRow->getColumn('nb_actions_per_visit_returning'); + if (false !== $value) { + $firstRow->setColumn('nb_actions_per_visit_returning', $numberFormatter->formatNumber($value, 1)); + } + + $value = $firstRow->getColumn('bounce_rate_returning'); + if (false !== $value) { + $firstRow->setColumn('bounce_rate_returning', $numberFormatter->formatNumber($value, $precision = 1)); + } + } + }; + } + } + + private function getSparklineTranslations() + { + $translations = array( + 'nb_visits_returning' => 'ReturnVisits', + 'nb_actions_returning' => 'ReturnActions', + 'nb_actions_per_visit_returning' => 'ReturnAvgActions', + 'avg_time_on_site_returning' => 'ReturnAverageVisitDuration', + 'bounce_rate_returning' => 'ReturnBounceRate', + ); + + foreach ($translations as $metric => $key) { + $translations[$metric] = Piwik::translate('VisitFrequency_' . $key); + } + + return $translations; + } + + private function addSparklineColumns(Sparklines $view) + { + $view->config->addSparklineMetric(array('nb_visits_returning')); + $view->config->addSparklineMetric(array('avg_time_on_site_returning')); + $view->config->addSparklineMetric(array('nb_actions_per_visit_returning')); + $view->config->addSparklineMetric(array('bounce_rate_returning')); + $view->config->addSparklineMetric(array('nb_actions_returning')); + } + } diff --git a/plugins/VisitFrequency/Widgets.php b/plugins/VisitFrequency/Widgets.php deleted file mode 100644 index 53a5ddcd47..0000000000 --- a/plugins/VisitFrequency/Widgets.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\VisitFrequency; - -class Widgets extends \Piwik\Plugin\Widgets -{ - protected $category = 'General_Visitors'; - - public function init() - { - $this->addWidget('VisitFrequency_WidgetOverview', 'getSparklines'); - $this->addWidget('VisitFrequency_WidgetGraphReturning', - 'getEvolutionGraph', - array('columns' => array('nb_visits_returning'))); - } - -} diff --git a/plugins/VisitFrequency/lang/en.json b/plugins/VisitFrequency/lang/en.json index d157e0a88c..39b1879852 100644 --- a/plugins/VisitFrequency/lang/en.json +++ b/plugins/VisitFrequency/lang/en.json @@ -12,13 +12,13 @@ "ColumnUniqueReturningVisitors": "Unique returning visitors", "ColumnReturningUsers": "Returning Users", "PluginDescription": "Reports metrics about your first time new visitors and returning visitors.", - "ReturnActions": "%s actions by the returning visits", - "ReturnAverageVisitDuration": "%s average visit duration for returning visitors", - "ReturnAvgActions": "%s actions per returning visit", - "ReturnBounceRate": "%s returning visits have bounced (left the website after one page)", + "ReturnActions": "actions by the returning visits", + "ReturnAverageVisitDuration": "average visit duration for returning visitors", + "ReturnAvgActions": "actions per returning visit", + "ReturnBounceRate": "returning visits have bounced (left the website after one page)", "ReturningVisitDocumentation": "A returning visit is (as opposed to a new visit) made by someone who has visited the website at least once before.", "ReturningVisitsDocumentation": "This is an overview of the returning visits.", - "ReturnVisits": "%s returning visits", + "ReturnVisits": "returning visits", "SubmenuFrequency": "Frequency", "WidgetGraphReturning": "Returning Visits Over Time", "WidgetOverview": "Frequency Overview" diff --git a/plugins/VisitFrequency/templates/_sparklines.twig b/plugins/VisitFrequency/templates/_sparklines.twig deleted file mode 100644 index 9c59efb811..0000000000 --- a/plugins/VisitFrequency/templates/_sparklines.twig +++ /dev/null @@ -1,39 +0,0 @@ - -{% if not isWidget %} -<div class="row"> - <div class="col-md-6"> -{% endif %} - - <div class="sparkline"> - {{ sparkline(urlSparklineNbVisitsReturning) }} - {{ 'VisitFrequency_ReturnVisits'|translate("<strong>"~nbVisitsReturning|number~"</strong>")|raw }} - </div> - <div class="sparkline"> - {{ sparkline(urlSparklineNbActionsReturning) }} - {{ 'VisitFrequency_ReturnActions'|translate("<strong>"~nbActionsReturning|number~"</strong>")|raw }} - </div> - <div class="sparkline"> - {{ sparkline(urlSparklineActionsPerVisitReturning) }} - {{ 'VisitFrequency_ReturnAvgActions'|translate("<strong>"~nbActionsPerVisitReturning|number(1)~"</strong>")|raw }} - </div> - - {% if not isWidget %} - </div> - <div class="col-md-6"> - {% endif %} - - <div class="sparkline"> - {{ sparkline(urlSparklineAvgVisitDurationReturning) }} - {% set avgVisitDurationReturning=avgVisitDurationReturning|sumtime %} - {{ 'VisitFrequency_ReturnAverageVisitDuration'|translate("<strong>"~avgVisitDurationReturning~"</strong>")|raw }} - </div> - <div class="sparkline"> - {{ sparkline(urlSparklineBounceRateReturning) }} - {{ 'VisitFrequency_ReturnBounceRate'|translate("<strong>"~bounceRateReturning|percent~"</strong>")|raw }} - </div> - {% include "_sparklineFooter.twig" %} - -{% if not isWidget %} - </div> -</div> -{% endif %} diff --git a/plugins/VisitFrequency/templates/getSparklines.twig b/plugins/VisitFrequency/templates/getSparklines.twig deleted file mode 100644 index fd158c8329..0000000000 --- a/plugins/VisitFrequency/templates/getSparklines.twig +++ /dev/null @@ -1 +0,0 @@ -{% include "@VisitFrequency/_sparklines.twig" %}
\ No newline at end of file diff --git a/plugins/VisitFrequency/templates/index.twig b/plugins/VisitFrequency/templates/index.twig deleted file mode 100644 index 6abd255b17..0000000000 --- a/plugins/VisitFrequency/templates/index.twig +++ /dev/null @@ -1,9 +0,0 @@ -{{ postEvent("Template.headerVisitsFrequency") }} - -<h2 piwik-enriched-headline data-graph-id="VisitFrequency.getEvolutionGraph">{{ 'VisitFrequency_ColumnReturningVisits'|translate }}</h2> - {{ graphEvolutionVisitFrequency|raw }} -<br/> - -{% include "@VisitFrequency/_sparklines.twig" %} - -{{ postEvent("Template.footerVisitsFrequency") }} |